擅长:python、mysql、java
<p>Python附带了一个名为smtplib的很棒的模块。它用于简单的邮件传输协议。在</p>
<pre><code>import smtplib
sender = 'from@fromdomain.com'
receivers = ['to@todomain.com']
message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print("Successfully sent email")
except SMTPException:
print("Error: unable to send email")
</code></pre>
<p>代码信用<a href="http://www.tutorialspoint.com/python/python_sending_email.htm" rel="nofollow">http://www.tutorialspoint.com/python/python_sending_email.htm</a></p>