欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python smtplib发email

程序员文章站 2022-04-19 23:25:49
#!/usr/bin/env python #coding: utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header sender = 'tom' receiver = ['j... ......
#!/usr/bin/env python

#coding: utf-8  



import smtplib  

from email.mime.text import mimetext  

from email.header import header  

  

sender = 'tom'  

receiver = ['john@sina.com', 'lili@163.com']  

subject = 'python email test'  

smtpserver = 'smtp.sina.com'  

username = 'yourusername'  

password = 'yourpassword'  



msg = mimetext('你好','text','utf-8')#中文需参数‘utf-8’,单字节字符不需要  

msg['subject'] = header(subject, 'utf-8')  



smtp = smtplib.smtp()  

smtp.connect(smtpserver)  

smtp.login(username, password)  

smtp.sendmail(sender, receiver, msg.as_string())  

smtp.quit()