gpt4 book ai didi

python : send data of form to one email address

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:13 25 4
gpt4 key购买 nike

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

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

谢谢:)

最佳答案

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

关于 python : send data of form to one email address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11287606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com