Error sending e-mail via SMTP server on App Engine development server

前端 未结 5 1580
北荒
北荒 2020-12-31 08:25

I am trying to send Email using this sample code and these command-line options:

dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@g         


        
相关标签:
5条回答
  • 2020-12-31 09:00

    The Google account being used to send emails from an application must have some security settings disabled in https://security.google.com/settings.

    • Disable access for less secure apps : Access for less secure apps: Turn On

    If you continue to have authentication issues you may have to review the Devices & activity at the https://security.google.com/settings/security/activity

    0 讨论(0)
  • 2020-12-31 09:10

    dev_appserver.py doesn't support TLS which is required by Gmail. You can enable it by adding a few lines in api/mail_stub.py:

    # After smtp.connect(self._smtp_host, self._smtp_port)
    smtp.ehlo()
    smtp.starttls()
    smtp.ehlo()
    

    Note! That's the quick and dirty solution. You should add some kind of flag to tell it whether you want to use TLS or not, as it is not always desired.

    0 讨论(0)
  • 2020-12-31 09:10

    @Raymond

    Execute the following command in the Terminal:

    find / -name "mail_stub.py" -type f 2>/dev/null
    

    In my case it returns:

    /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py
    
    0 讨论(0)
  • 2020-12-31 09:11

    For anyone looking up this answer in 2018 or later: this workaround is no longer needed. You can now use the command like the original poster wrote it:

    dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@gmail.com --smtp_password=yyy myapp
    
    0 讨论(0)
  • 2020-12-31 09:14

    The other methods are no longer necessary:

    Setting the following in /appengine/api/mail_stub.py

    if self._allow_tls and smtp.has_extn ('STARTTLS'):
      smtp.starttls ()
    

    works for me on appengine sdk version 1.9.15

    0 讨论(0)
提交回复
热议问题