After looking through many of the mail modules, I've settled on Mail::Sender. I need authenticated SMTP, so that drops out several other options and I don't want to pull in multiple modules manually to get the necessary authenticating done
My problem comes in with using Mail::Sender from within CGI scripts. I copied the exact same code snippet to a command line script and never get the same problem. The problem is simple: for every few emails sent, Mail::Sender fails with a "Service not available, connection not established" error. The culprit-type script is below. Does Mail::Sender change behaviour under CGI, because I have never once got this error from the command line version:
#!c:/perl/bin/perl -w
$|++;
use strict;
use Mail::Sender;
$Mail::Sender::NO_X_MAILER = 1;
$Mail::Sender::NO_MESSAGE_ID = 1;
open my $log, '>>', 'c:/logcmd.log'
or die "open failed: $!";
my $email = Mail::Sender->new( {
smtp => 'smtp.somewhere.net',
auth => 'LOGIN',
authid => 'someuser',
authpwd => 'somepasswd',
on_errors => 'die',
debug => $log
} );
$email->Open( {
from => 'MyName <me@myserver.com>',
to => 'TheirName <them@theirserver.com>',
subject => 'Some Subject'
} );
$email->SendEnc(<<"END_EMAIL");
This is the body of the email message. Yes, that is right.
foo bar baz.... blah.
END_EMAIL
$email->Close();
close $log;