Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris


by Rodster001 (Pilgrim)
on Jan 26, 2012 at 22:02 UTC ( #950227=perlquestion: print w/replies, xml ) Need Help??
Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Amazon's SES (simple email service) via SMTP. This should be a pretty simple straight forward thing to set up (which I have done with other similar services such as

Of course, I am running into problems. I have tried Mail::Sender but it is just hanging. SES uses nonstandard port of 465 but I am able to define that. I am able to connect from the command line:

# telnet 465 Trying Connected to Escape character is '^]'. HELO adsf Connection closed by foreign host.
SES says it requires TLS with SMTP. Mail::Sender doesn't seem to have support for this built in. So, I tried Email::Send::SMTP::TLS, but I am getting similar problems.

Both packages just hang when trying to connect to the remote server for a minute or two and then disconnect with "connection not established" (Mail::Sender) or "Could not connect to SMTP server" (Email::Send::SMTP::TLS).

Here is what I am doing with Mail::Sender (I tried all the auth methods it supports with no luck):

open my $DEBUG, ">>smtp_log" or print STDERR "Unable to open smtp_log" +; ## Send an email my $sender = new Mail::Sender { from => $from, smtp => $server, port => '465', auth => 'login', authid => $username, authpwd => $password, debug => $DEBUG, debug_level => 4, } or print STDERR "Can't create Mail::Sender object: $Mail::Sender::Er +ror\n"; $Mail::Sender::NO_X_MAILER = 1; $sender->Open({ to => $to, subject => "Test Email", ctype => 'text/plain', encoding => "quoted-printable", }) or print STDERR "Can't open the message: $sender->{'error_msg'}\n"; my $msg = "This is a test email with Mail::Sender\n\n"; $sender->SendEnc($msg); close $DEBUG;
And Email::Send::SMTP::TLS:
my $server = ""; my $port = 465; my $mailer = Email::Send->new( { mailer => 'SMTP::TLS', mailer_args => [ Host => $server, Port => $port, User => $username, Password => $password, Hello => '', ] } ); use Email::Simple::Creator; my $email = Email::Simple->create( header => [ From => $from, To => $to, Subject => 'Test Email', ], body => 'This is a test', ); eval { $mailer->send($email) }; die "Error sending email: $@" if $@;
Because they are both hanging it really makes me think it is a port issue. But the fact that I can connect from the command line and that both packages are hanging (even though I am specifying the port) really has me at a loss. I know this is not a lot to go on, but any ideas, insight or other packages I should try would be greatly appreciated!


Replies are listed 'Best First'.
Re: SMTP and TLS
by thewebsi (Scribe) on Jan 27, 2012 at 01:19 UTC
    HELO adsf
    Connection closed by foreign host.

    The telnet test certainly does away with any theory that the port might be blocked. It is clearly open, and there is a listener on the other end. However, your scripts go much further than this, actually attempting to negotiate an encrypted connection, log in, and even send a message. The script is likely failing at a later stage.

    At this point, I would want to test the server to see if it indeed supports TLS, the authentication information you have is correct, and that you are allowed to use it to send messages. The server might be set up to hang if it's not happy with the transaction (this is a common way to slow down spambots). Unfortunately, this behaviour may mean that you won't get much in the way of useful error messages (as you've already noticed).

    I've used this guide before to test SMTP servers for access. It uses command-line tools, but you can certainly use Net::SMTP for example to achieve the same. Note that this is unlikely to be an issue particular to Perl.

      I did get a response from Amazon:
      At the moment, the Amazon SES SMTP interface supports connections wrapped with TLS. This means that the telnet command won't work as a troubleshooting mechanism. With OpenSSL installed, try the following:

      openssl s_client -quiet -crlf -connect

      After establishing a TLS connection, we will provide the typical SMTP banner.

      So, I gave that a shot and:
      # openssl s_client -quiet -crlf -connect
      depth=2 /C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
      verify error:num=20:unable to get local issuer certificate
      verify return:0
      220 ESMTP SimpleEmailService-200596653
      221 Bye
      I need to do a little bit of investigation, not sure if that issue is on my end or theirs. I also tried another package (Net::SMTP::TLS). But it too just hangs on connect.

      Let me know if you have any ideas, otherwise I will post what I find here.

Re: SMTP and TLS
by Rodster001 (Pilgrim) on Jan 27, 2012 at 01:24 UTC
    After a little investigation I believe that the problem is likely that the Amazon server is not greeting with a 220 welcome message (as you can see from the telnet session (in orig post) that it doesn't send one). So my clients are hanging, waiting for the response.

    I suppose the best solution (if I want to stick with Amazon) is to modify one of these clients. *sigh*

      I ended up configuring sendmail to work with Amazon's SES

      First set up a secure tunnel

      And then configure sendmail

      Then I can just use Mail::Sender again. This set up seems to work nicely. I hate not being able to resolve the exact problem (above) but I need to move onto other things :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950227]
Approved by Eliya
[Corion]: (and also, writing yet another FFmpeg module just to wrap system() and grep through its output isn't all that great ...)
[erix]: cut out advertisements from movies? :)
[erix]: robably not possible (or it would have been done already)
[Corion]: erix: Oooh - yeah, that would be a good application of this, true (except that I don't consume movies-with- separate- advertisements that much nowadays :) )
[erix]: yes, it's old annoyance :)
[Corion]: erix: I think it's basically quite possible through a variety of means - change in audio level (advertisements are usually louder), common "advertisement starting" blocks, fade in/out of TV logo

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2018-05-24 11:14 GMT
Find Nodes?
    Voting Booth?