简体   繁体   English

从python webapp2 Google App Engine发送电子邮件

[英]Send email from python webapp2 Google App Engine

i am trying to send an email from my application. 我正在尝试从我的应用程序发送电子邮件。 The code run successfully with out error. 代码运行成功,没有错误。 But it do not send the email. 但它不发送电子邮件。 It show this message on Console. 它在Console上显示此消息。

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

The sample code provided by the google is: 谷歌提供的示例代码是:

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()

That's because the dev_appserver by default doesn't send out real mails. 那是因为默认情况下dev_appserver不发送真实邮件。

Email sending will work when you push to a live server , for eg: 当您推送到实时服务器时 ,电子邮件发送将起作用 ,例如:

appcfg update /path/to/app/

But like the error message points out, you'll have to use the --enable_sendmail flag if you have sendmail installed on your system or use smtp flags, for eg: 但是,正如错误消息指出的那样,如果您在系统上安装了sendmail或使用smtp标志,则必须使用--enable_sendmail标志,例如:

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

or another eg using gmail as smtp provider 或另一个例如使用gmail作为smtp提供者

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

More explanation here: https://cloud.google.com/appengine/docs/python/mail/ 这里有更多解释: https//cloud.google.com/appengine/docs/python/mail/

Mail and the development server 邮件和开发服务器

The development server can be configured to send email messages directly from your computer when you test a feature of your app that sends messages. 可以将开发服务器配置为在测试发送消息的应用程序功能时直接从计算机发送电子邮件。 You can configure the development server to use an SMTP server of your choice. 您可以将开发服务器配置为使用您选择的SMTP服务器。 Alternatively, you can tell the development server to use Sendmail, if Sendmail is installed on your computer and set up for sending email. 或者,您可以告诉开发服务器使用Sendmail,如果您的计算机上安装了Sendmail并设置了发送电子邮件。

If you do not configure an SMTP server or enable Sendmail, when your app calls the Mail service, the development server will log the contents of the message. 如果未配置SMTP服务器或启用Sendmail,则当应用程序调用邮件服务时,开发服务器将记录邮件的内容。 The message will not actually be sent. 实际上不会发送该消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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