# -*- coding: utf-8 -*-
'''
发送html文本邮件
小五义:http://www.com/xiaowuyi
'''
import smtplib
from email.mime.text import MIMEText
mailto_list=['yanchangjie@gyyx.cn','wangyuqian@gyyx.cn','huanghualiang@gyyx.cn']
mail_host="mail.gyyx.cn" #设置服务器
mail_user="huanghualiang" #用户名
mail_pass="hhl77915" #口令
mail_postfix="gyyx.cn" #发件箱的后缀
def send_mail(to_list,sub,content): #to_list:收件人;sub:主题;content:邮件内容
me="hello"+"<"+mail_user+"@"+mail_postfix+">" #这里的hello可以任意设置,收到信后,将按照设置显示
msg = MIMEText(content,_subtype='html',_charset='gb2312') #创建一个实例,这里设置为html格式邮件
msg['Subject'] = sub #设置主题
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
s = smtplib.SMTP()
s.connect(mail_host) #连接smtp服务器
s.login(mail_user,mail_pass) #登陆服务器
s.sendmail(me, to_list, msg.as_string()) #发送邮件
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(mailto_list,"hello","<a href='http://www.com/xiaowuyi'>小五义</a>"):
print "发送成功"
else:
print "发送失败"
python 发送邮件
原创
©著作权归作者所有:来自51CTO博客作者smart818的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Python多线程
下一篇:Mysql 主从复制相关
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python 发送邮件 和 发送带附件邮件
平时运行一些脚本,需要把结果发送到邮箱,可以用python来处理,如下:1,有邮
sendmail mail python 邮件服务器 发送邮件 -
【python】发送邮件
从网上找了一些用python发邮件的教程,学习一下:1、发送普通的文
python javascript 服务器 用户名 邮件服务器