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 に答える