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(
# 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())

Posted in 未分类