贴上一段用Python开发的发送邮件程序

#coding=UTF-8 
 
import smtplib 
from email.mime.text import MIMEText 
 
smtp_host="smtp.163.com" 
smtp_port="25" 
 
mail_user="[email protected]" 
mail_password="1111222" 
 
def send_mail(to_list,subject,content): 
charset = 'UTF-8' 
 
msg = MIMEText(content,_subtype='html',_charset=charset) 
msg['Subject'] = subject 
msg['From'] = mail_user 
msg['To'] = ','.join(to_list) 
 
try: 
s = smtplib.SMTP(smtp_host, smtp_port) 
s.ehlo() 
#s.starttls() 
#s.ehlo() 
s.login(mail_user, mail_password) 
print 'success in login...' 
s.sendmail(mail_user, to_list, msg.as_string()) 
s.close() 
 
print 'success in sending...' 
return True 
 
except Exception, e: 
print 'failed in sending...' 
print str(e) 
 
return False 
 
send_mail('[email protected],[email protected]'.split(','),'我的邮件发送测试','THIS IS A TEST MAIL 这是测试邮件的内容')

 



发布评论

分享到:

IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

弥补wxpython无背景图片缺陷讲解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。