【问题标题】:Send email from python webapp2 Google App Engine从 python webapp2 Google App Engine 发送电子邮件
【发布时间】:2016-12-04 21:43:39
【问题描述】:

我正在尝试从我的应用程序发送电子邮件。代码成功运行,没有错误。但它不发送电子邮件。它在控制台上显示此消息。

You are not currently sending out real email. 
If you have sendmail installed you can use it by using the 
server with --enable_sendmail

google提供的示例代码为:

message = mail.EmailMessage(
                    sender="shaizi9687@gmail.com",
                    subject="Your account has been approved")

message.to = "ABC <shahzebakram@hotmail.com>"
message.body = """Dear Albert:
Your example.com account has been approved.  You can now visit
http://www.example.com/ and sign in using your Google Account to
access new features.
Please let us know if you have any questions.
The example.com Team
"""
message.send()

【问题讨论】:

    标签: python email google-app-engine webapp2


    【解决方案1】:

    这是因为默认情况下 dev_appserver 不会发送真正的邮件。

    电子邮件发送将在您推送到实时服务器时起作用,例如:

    appcfg update /path/to/app/
    

    但就像错误消息指出的那样,如果您的系统上安装了 sendmail 或使用 smtp 标志,则必须使用 --enable_sendmail 标志,例如:

    dev_appserver /path/to/app/ --enable_sendmail=yes
    

    或另一个例如使用 gmail 作为 smtp 提供程序

    dev_appserver /path/to/app --smtp_host=smtp.gmail.com --smtp_port=465 \
    --smtp_user=user@gmail.com --smtp_password=password 
    

    更多解释在这里:https://cloud.google.com/appengine/docs/python/mail/

    邮件和开发服务器

    开发服务器可以配置为发送电子邮件 当您测试应用程序的一项功能时,直接从您的计算机 发送消息。您可以将开发服务器配置为使用 您选择的 SMTP 服务器。或者,您可以告诉 使用 Sendmail 的开发服务器,如果您的服务器上安装了 Sendmail 计算机并设置发送电子邮件。

    如果您没有配置 SMTP 服务器或启用 Sendmail,当您的 应用程序调用邮件服务,开发服务器将记录 消息的内容。该消息实际上不会被发送。

    【讨论】:

      猜你喜欢
      • 2010-10-27
      • 2012-04-10
      • 2011-03-21
      • 1970-01-01
      • 2011-02-21
      • 2016-10-27
      • 2023-04-05
      • 2014-10-31
      • 2011-04-05
      相关资源
      最近更新 更多