Search code examples
perlemailgmailamazon-ses

Net::SMTP::SSL (via gmail and amazon smtp) - 'Connection Closed' when sending email with attachment


I have a perl export script which generates a .csv file and then emails it to the user. I've gone down this route because we do not want the user to have to wait on a specific page for the export to finish, instead allowing it to be exported in the background.

However, when the csv is attached and the email sent I get the following error:

[Net::SMTP::SSL] Connection closed

I can't put a lot of the code here, but I can at least show you what part of the code is reporting this error. I am wondering if anyone here knows why this might be happening, or an easy way to debug it.

Here's the code block for sending the email (with comment for where error is reported):

my $mailer = new Net::SMTP::SSL($smtp, Port => $port) or die "Cannot create a SSL mailer instance!\n";
$mailer->auth($user, $pass) or die ("Can't authenticate");

$mailer->mail($email) or die $mailer->message;
$mailer->to(split(',', $to)) or die $mailer->message;
$mailer->data() or die $mailer->message;
$mailer->datasend($msg->as_string) or die $mailer->message; # Connection closed
$mailer->dataend() or die $mailer->message;
$mailer->quit() or die $mailer->message;

Please let me know if there's any other information needed. I will try and provide what I can. This is difficult to resolve because the error is so ambiguous.

NOTE: The emails successfully send when removing the offending attachment, and sometimes send depending on the csv content.


Solution

  • There seems to be an unexpected EOF report by the debugger. This is a duplicate Net::SMTP: Net::Cmd::_is_closed(): unexpected EOF on command channel [perl]

    New Error: Net::SMTP::SSL: Net::Cmd::datasend(): unexpected EOF on command channel