码迷,mamicode.com
首页 > 编程语言 > 详细

通过SMTP发送邮件的Python代码

时间:2014-08-17 18:16:23      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   art   div   

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

#coding=UTF-8

import smtplib
from email.mime.text import MIMEText

smtp_host="smtp.163.com"
smtp_port="25"

mail_user="yhtt2020@163.com"
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(597964799@qq.com,yhsol1@163.com.split(,),我的邮件发送测试,THIS IS A TEST MAIL 这是测试邮件的内容)

 



通过SMTP发送邮件的Python代码,布布扣,bubuko.com

通过SMTP发送邮件的Python代码

标签:style   blog   color   os   io   ar   art   div   

原文地址:http://www.cnblogs.com/yjken/p/3917949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!