我使用Python在Google App Engine中编写表单,用户可以将数据输入到表单中。输入后,我希望将这些数据发送到一个人的电子邮箱。例如:example@gmail.com。
我的问题是:在Python中,它是否具有简单的功能(我可以在Google App Engine上使用此功能)来发送电子邮件?
谢谢:)
答案 0 :(得分:3)
Python确实有一个用于传输电子邮件的邮件包。
下面是Python docs
中的示例# 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()
此外,应用引擎也有mail 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
""")