python发邮件例子,python发邮件,来自python官方的例


来自python官方的例子,做了翻译

# 导入smtplib模块import smtplib# 导入MIMEText类,使用此类封装邮件信息from email.mime.text import MIMEText# 打开文件读取邮件内容# the text file contains only ASCII characters.fp = open(textfile, 'rb')msg = MIMEText(fp.read())fp.close()# me == 发件人地址# you == 收件人地址msg['Subject'] = 'The contents of %s' % textfilemsg['From'] = memsg['To'] = you# 使用SMTPserver发送邮件# envelope header.s = smtplib.SMTP('localhost')s.sendmail(me, [you], msg.as_string())s.quit()

评论关闭