使用Ubuntu 14.04在EC2上烧瓶邮件SMTPServerDisconnected错误

时间:2016-01-28 02:26:22

标签: python email amazon-ec2 ubuntu-14.04 flask-mail

我有一个烧瓶应用程序使用烧瓶邮件发送电子邮件,使用相同的邮件设置,我可以从我的MacBook Pro本地成功发送电子邮件。但是当我在Ubuntu14.04上的EC2上使用相同的电子邮件设置部署相同的代码时,我无法发送电子邮件并收到以下错误:

send: 'ehlo flasks-app-server1.localdomain\r\n'
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/srv/www/flasky/app/email.py", line 9, in send_async_email
    mail.send(msg)
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 415, in send
    with self.connect() as connection:
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 123, in __enter__
    self.host = self.configure_host()
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 142, in configure_host
    host.starttls()
  File "/usr/lib/python2.7/smtplib.py", line 642, in starttls
    self.ehlo_or_helo_if_needed()
  File "/usr/lib/python2.7/smtplib.py", line 542, in ehlo_or_helo_if_needed
    if not (200 <= self.ehlo()[0] <= 299):
  File "/usr/lib/python2.7/smtplib.py", line 413, in ehlo
    self.putcmd(self.ehlo_msg, name or self.local_hostname)
  File "/usr/lib/python2.7/smtplib.py", line 341, in putcmd
    self.send(str)
  File "/usr/lib/python2.7/smtplib.py", line 333, in send
    raise SMTPServerDisconnected('please run connect() first')
SMTPServerDisconnected: please run connect() first

我用Google搜索了大约两个小时,但找不到解决方法。有什么帮助吗?谢谢!

2 个答案:

答案 0 :(得分:1)

我明白了。我的AWS SES需要验证不同地区的电子邮件。我没有为我正在使用的新地区这样做。

答案 1 :(得分:1)

我通过在安全组和计算机上同时打开SMTPS端口465来解决此问题。