- import smtplib
- from email.mime.text import MIMEText
- textfile='aa.txt'
- s = smtplib.SMTP('smtp.126.com')
- s.set_debuglevel(True)
- s.login('xxx@126.com','xxx')
- fp = open(textfile,'r')
- msg = MIMEText(fp.read())
- fp.close()
- msg['Subject'] = 'The content of %s' % textfile
- msg['From']='xxx@126.com'
- msg['To']='xxx@126.com'
- s.send_message(msg)
- s.quit()
- #该片段来自于http://www.codesnippet.cn/detail/0608201513367.html
来源: http://www.codesnippet.cn/detail/0608201513367.html