Using Perl to send emails from remote server


On DigitalOcean I’ve got a vps running MIAB at and a “Web App” server on another vps at

I want to send emails from the web app using a Perl script.

I’m using the MIAB DNS server for both domain names. With the MIAB server I can send and receive email using my Mac Mini “Mail” app so that’s working great.

I’ve edited a perl script that attempts to authenticate a user and send a simple email from but it is not passing the auth stage. I get this error:

Error sending email: failed AUTH: Command unknown: 'AUTH

Anyone have any ideas on what I’m doing wrong?

Here’s the script on the web app server, the mail.log from the MIAB, what the script outputs when run:


use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTPS;
use Try::Tiny;

my $transport = Email::Sender::Transport::SMTPS->new(
		host => '',
		ssl  => 'starttls',
		sasl_username => '',
		sasl_password => 'xxxx',
		debug => 1, # or 1

use Email::Simple::Creator; # or other Email::
my $message = Email::Simple->create(
		header => [
				From    => '',
				To      => '',
				Subject => 'cherrypc perl test',
		body => 'This is the test.',

try {
		sendmail($message, { transport => $transport });
} catch {
		die "Error sending email: $_";

MIAB mail.log:

Apr 16 13:17:10 box postfix/submission/smtpd[31729]: connect from[]
Apr 16 13:17:10 box postfix/submission/smtpd[31729]: lost connection after EHLO from[]
Apr 16 13:17:10 box postfix/submission/smtpd[31729]: disconnect from[] perl script output

root@cherrypc:/usr/lib/cgi-bin# perl
Net::SMTPS>>> Net::SMTPS(0.06)
Net::SMTPS>>> IO::Socket::IP(0.37)
Net::SMTPS>>> IO::Socket(1.38)
Net::SMTPS>>> IO::Handle(1.35)
Net::SMTPS>>> Exporter(5.72)
Net::SMTPS>>> Net::SMTP(3.10)
Net::SMTPS>>> Net::Cmd(3.10)
Net::SMTPS=GLOB(0x33b7958)<<< 220 ESMTP Hi, I’m a Mail-in-a-Box (Ubuntu/Postfix; see
Net::SMTPS=GLOB(0x33b7958)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x33b7958)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x33b7958)<<< 250-SIZE 134217728
Net::SMTPS=GLOB(0x33b7958)<<< 250-VRFY
Net::SMTPS=GLOB(0x33b7958)<<< 250-ETRN
Net::SMTPS=GLOB(0x33b7958)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x33b7958)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x33b7958)<<< 250 DSN
Error sending email: failed AUTH: Command unknown: ‘AUTH’

Trace begun at /usr/local/share/perl/5.22.1/Email/Sender/Transport/ line 98
Email::Sender::Transport::SMTPS::_throw(‘Email::Sender::Transport::SMTPS=HASH(0x24d8b80)’, ‘failed AUTH’, ‘Net::SMTPS=GLOB(0x33b7958)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Transport/ line 71
Email::Sender::Transport::SMTPS::_smtp_client(‘Email::Sender::Transport::SMTPS=HASH(0x24d8b80)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Transport/ line 107
Email::Sender::Transport::SMTPS::send_email(‘Email::Sender::Transport::SMTPS=HASH(0x24d8b80)’, ‘Email::Abstract=ARRAY(0x3023ae0)’, ‘HASH(0x3023ca8)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Role/ line 45
Email::Sender::Role::CommonSending::try {…} at /usr/share/perl5/Try/ line 92
eval {…} at /usr/share/perl5/Try/ line 83
Try::Tiny::try(‘CODE(0x307b370)’, ‘Try::Tiny::Catch=REF(0x3023d38)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Role/ line 58
Email::Sender::Role::CommonSending::send(‘Email::Sender::Transport::SMTPS=HASH(0x24d8b80)’, ‘Email::Abstract=ARRAY(0x3023ae0)’, ‘HASH(0x3069a30)’) called at /usr/local/share/perl/5.22.1/Email/Sender/ line 119
Email::Sender::Simple::send_email(‘Email::Sender::Simple’, ‘Email::Abstract=ARRAY(0x3023ae0)’, ‘HASH(0x3023cf0)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Role/ line 45
Email::Sender::Role::CommonSending::try {…} at /usr/share/perl5/Try/ line 92
eval {…} at /usr/share/perl5/Try/ line 83
Try::Tiny::try(‘CODE(0x3023b58)’, ‘Try::Tiny::Catch=REF(0x3005228)’) called at /usr/local/share/perl/5.22.1/Email/Sender/Role/ line 58
Email::Sender::Role::CommonSending::send(‘Email::Sender::Simple’, ‘Email::Simple=HASH(0x3004f88)’, ‘HASH(0x3004ee0)’) called at /usr/share/perl5/Sub/Exporter/ line 18
Sub::Exporter::Util::ANON(‘Email::Simple=HASH(0x3004f88)’, ‘HASH(0x3004ee0)’) called at line 26
main::try {…} at /usr/share/perl5/Try/ line 92
eval {…} at /usr/share/perl5/Try/ line 83
Try::Tiny::try(‘CODE(0x2fd50b0)’, ‘Try::Tiny::Catch=REF(0x2f96d08)’) called at line 29


Ok, I learned a lot working on this and I still don’t know way more than I probably should but here’s what I did and a working perl script for those who might want or need one.

The script is running on a DigitalOcean vps with Ubuntu 16.04 and sending the email from another DigitalOcean vps running MIAB. You may have to install the perl modules referenced and first I needed to add my remote domain’s IP address to POSTFIX on the MIAB server like so:

Edit this file:
sudo nano /etc/postfix/

Look for this line:
mynetworks = [::ffff:]/104 [::1]/128

Add the remote server IP like this (example IP used:
mynetworks = [::ffff:]/104 [::1]/128

Save the file then reload postfix:
sudo postfix reload

Here’s the perl script. I put mine in the “/usr/lib/cgi-bin/” directory:


use Net::SMTP;
use MIME::Base64;

# Server and User Authentication:
my $smtpserver = '';
my $user = '';
my $password = 'your-password';

my $from ='';

# Test email data:
my $send_to = '';
my $send_subj = 'Perl on MAIB Test';
my $html_msg = '<h3>This is the HTML test message</h3>';

&doMail ($send_to, $send_subj, $html_msg);

sub doMail {

	my ($to, $subj, $msg) = @_;	
	my $smtp = Net::SMTP->new(
		   Timeout => 30,
		   Debug   => 0,

	$smtp->datasend("AUTH LOGIN\n");

#  -- Login to SMTP --
	# Enter sending email box address username below.
	$smtp->datasend(encode_base64($user) );

	#  -- Enter email box address password below.   login to SMTP --
	$smtp->datasend(encode_base64($password) );



#  -- This part creates the SMTP headers you see --
	$smtp->datasend("From: $from \n");
	$smtp->datasend("To: $to \n");
	$smtp->datasend("Content-Type: text/html \n");
	$smtp->datasend("Subject: $subj");

	# then a line break to separate headers from message body

	# the html message:


	if ($smtp->error) {print $smtp->error}

	else {print "Message Sent \n"}