Perl – Sending Email with NET::SMTP using username and password

First of all double check that Authen::SASL is an installed module.. If you are not getting emails this could be why – it doesnt provide an error that is understandable!

### ENSURE Authen::SASL is installed
use Net::SMTP;
use strict;
use warnings;

my $host= 'yourhostname';
my $username= "yourpop3username";
my $password = "yourpassword";

my $from = 'bob\';
my $to = '';
my $DOMAIN = "";

my $smtp = Net::SMTP->new($host, Hello =>$DOMAIN, Timeout => 60) or die "Failed to Open SMTP Connection : $!";
$smtp->auth($username, $password) or die "Failed to authenticate";

my $subject = "Build";
my $emailBody = "This is the body...\n BOB";

$smtp->mail("$from"); ## FROM
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from \n");
$smtp->datasend("Subject: $subject \n");

These links were useful also: