简体   繁体   中英

flask-mail SMTPServerDisconnected error on EC2 with Ubuntu 14.04

I have a flask app using flask-mail to send out emails, using the same mail setting, I can successfully send out emails locally from my MacBook Pro. But when I deploy the same code with same email setting on EC2 on Ubuntu14.04, I cannot send emails and got the following error:

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

I have googled this for about two hours and could not find a solution. Any help, please? Thanks!!

I figured it out. I AWS SES needs to verify the email for different region. I did not do that for the new region I am using.

我通过在安全组和机器上打开 SMTPS 端口解决了这个问题:465。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM