可以利用smtplib模块来实现发送邮件的功能,一个比较简单的实例代码如下:
# 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.
# create a text/plain message
msg = mimetext(“some content”)
me = you = ‘somebody@somewhere.com’
# me == the sender’s email address
# you == the recipient’s email address
msg[‘subject’] = ‘the contents of somebody’
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()