2

我使用 Python 在 Google App Engine 中编写了一个表单,用户可以输入数据来形成表单。输入后,我希望将此数据发送到一个人的电子邮件。例如:example@gmail.com。

我的问题是:在 Python 中,它是否具有简单的功能(我可以在 Google App Engine 上使用此功能)来发送电子邮件?

谢谢 :)

4

1 回答 1

3

Python 确实有一个用于传输电子邮件的邮件包。

下面是Python 文档中的一个示例

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
fp = open(textfile, 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()

此外,应用引擎还有一个邮件 API

from google.appengine.api import mail

mail.send_mail(sender="Example.com Support <support@example.com>",
              to="Albert Johnson <Albert.Johnson@example.com>",
              subject="Your account has been approved",
              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
""")
于 2012-07-02T03:57:14.730 回答