2019-10-04 Sending Mail with Perl

Here’s something that finally worked. To remember:

  1. Don’t use Net::SMTP::SSL
  2. Don’t use Net::SMTP::TLS
  3. Don’t use Net::SSLGlue::SMTP
  4. Use Net::SMTP
  5. Make use Authen::SASL is installed
  6. Make sure the mail contains all the necessary headers
  7. Look at the debug output!
  8. Don’t worry about SSL_version

Gaaah. This took way too long to figure out. So here’s my test script:

use Modern::Perl;
use Net::SMTP;
use Authen::SASL qw(Perl);
my $subject = "Hello";
my $to = 'kensanata@gmail.com';
my $user = 'notifications@alexschroeder.ch';
my $password = "*secret*";
my $host = "smtp.migadu.com:587";
my $from = 'notifications@alexschroeder.ch';
my $mail = <<EOT;
From: $from
To: $to
Subject: $subject

This is the mail.
my $verbose = 1;
my $smtp = Net::SMTP->new($host, Debug => 1);
# the following requires Authen::SASL!
$smtp->auth($user, $password);
if ($smtp->to($to)) {
} else {
  print "Error: ", $smtp->message();



I wonder whether I should switch my notifications from the GMail account to the Migadu account. I get the feeling that GMail (and maybe others as well) are too quick to mark the notifications as spam. But then again, who knows.

– Alex Schroeder 2019-10-04 16:40 UTC

Please make sure you contribute only your own work, or work licensed under the GNU Free Documentation License. Note: in order to facilitate peer review and fight vandalism, we will store your IP number for a number of days. See Privacy Policy for more information. See Info for text formatting rules. You can edit the comment page if you need to fix typos. You can subscribe to new comments by email without leaving a comment.

To save this page you must answer this question:

Please say HELLO.