Send mail using Perl script (TLS) for office 365

Thanks to Joshua F.

Following script will send the mail with TLS using office 365 smtp.

Note: you must have office 365 account.

first you need to install the Net::SMTP:TLS using cpan

[root@localhost ~]# cpan
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9402)
Enter 'h' for help.

cpan[1]> install Net::SMTP:TLS

create mail-test.pl file and copy following script to that file.

Note: Change Red mark contain.

#!/usr/bin/perl
use strict;
use Net::SMTP::TLS;  
 
#
my $mailer = new Net::SMTP::TLS(  
    'smtp.office365.com',
    Port    =>      587,  
    Hello   =>      '',
    User    =>      'Username-Email-ID',
    Password=>      'Password',
    Debug   => 1) || die "Cannot connect to smtp server";
 
$mailer->mail('From-Email-ID@example.com');
$mailer->to('To-Email-ID@example.com');
$mailer->data;  
$mailer->datasend("\n");  
$mailer->datasend("Sent from perl!");  
$mailer->dataend;  
$mailer->quit;
Advertisements
Posted in Office 365

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: