【问题标题】:Python : send data of form to one email addressPython:将表单数据发送到一个电子邮件地址
【发布时间】:2012-07-02 12:13:18
【问题描述】:

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

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

谢谢:)

【问题讨论】:

    标签: python google-app-engine email


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多