AWS SES 简单电子邮件服务,Zend 电子邮件超时错误
我使用 Amazon AWS SES 简单电子邮件服务为我的应用程序发送电子邮件。我使用 Zend Framework2 的以下代码发送电子邮件。以前工作正常,但现在我的 AWS EB EC2 实例出现以下错误。然而,在我的本地主机中,我仍然可以使用相同的代码和相同的 AWS SES 帐户来发送电子邮件,并且它现在在我的本地主机中仍然工作正常。
$sc_Zend_mail_smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
$sc_Zend_mail_smtpOptions->setHost($sc_server_email_host)
->setConnectionClass('login')
->setName($sc_server_email_host)
->setConnectionConfig(array(
'username' => $sc_server_email_account,
'password' => $sc_server_email_password,
'ssl' => 'tls',
'port' => 587
));
$sc_Zend_mail_transport = new \Zend\Mail\Transport\Smtp($sc_Zend_mail_smtpOptions);
问题出自 AWS EB EC2 ssl 设置吗?代码有什么问题?之前在AWS EC2上运行得很好。
错误信息是:
Fatal error: Uncaught exception 'Zend\Mail\Protocol\Exception\RuntimeException'
with message 'Connection timed out' in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php:209 S
tack trace: #0 /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(148): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://email-smt...')
#1/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(375): Zend\Mail\Protocol\Smtp->connect()
#2/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(361): Zend\Mail\Transport\Smtp->connect()
#3/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(372): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#4/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(229): in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php on line 209
I was using Amazon AWS SES simple email service to send emails for my application. I using the following codes of Zend framework2 to send emails. It worked fine before, but I got the following error in my AWS EB EC2 instance now. However in my localhost, I can still use the same code and the same AWS SES account to send emails and it is still working fine now in my localhost.
$sc_Zend_mail_smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
$sc_Zend_mail_smtpOptions->setHost($sc_server_email_host)
->setConnectionClass('login')
->setName($sc_server_email_host)
->setConnectionConfig(array(
'username' => $sc_server_email_account,
'password' => $sc_server_email_password,
'ssl' => 'tls',
'port' => 587
));
$sc_Zend_mail_transport = new \Zend\Mail\Transport\Smtp($sc_Zend_mail_smtpOptions);
Is the problem from AWS EB EC2 ssl setting ? What is wrong with the codes? It was working fine in AWS EC2 before.
The error message is:
Fatal error: Uncaught exception 'Zend\Mail\Protocol\Exception\RuntimeException'
with message 'Connection timed out' in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php:209 S
tack trace: #0 /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(148): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://email-smt...')
#1/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(375): Zend\Mail\Protocol\Smtp->connect()
#2/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(361): Zend\Mail\Transport\Smtp->connect()
#3/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(372): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#4/var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(229): in /var/app/current/utils/zendfw/ZendFw2/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php on line 209
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AWS EC2 中的服务器实例似乎不允许再设置旧端口。将端口设置移到 setConnectionConfig 数组之外确实可以使其在 AWS EB EC2 以及本地主机中再次正常工作。
It seems that server instance in AWS EC2 does not allow the old port set up any more. Moving the port setup outside setConnectionConfig array does make it work in AWS EB EC2 again as well as in localhost.