python发送邮件
来源:互联网 发布:宝宝计划软件 编辑:程序博客网 时间:2024/06/06 03:29
1 # -*- coding: UTF-8 -*- 2 ''' 3 发送txt文本邮件 4 http://www.cnblogs.com/liu-ke 5 ''' 6 import smtplib 7 from email.mime.text import MIMEText 8 mailto_list=['***@**.***'] 9 mail_host="smtp.****.com" #设置服务器10 mail_user="***@**.**" #用户名11 mail_pass="********" #口令 12 mail_postfix="***.com" #发件箱的后缀13 14 def send_mail(to_list,sub,content): 15 me="hello"+"<"+mail_user+"@"+mail_postfix+">" 16 msg = MIMEText(content,_subtype='plain',_charset='gb2312') 17 msg['Subject'] = sub 18 msg['From'] = me 19 msg['To'] = ";".join(to_list) 20 try: 21 server = smtplib.SMTP() 22 server.connect(mail_host) 23 server.login(mail_user,mail_pass) 24 server.sendmail(me, to_list, msg.as_string()) 25 server.close() 26 return True 27 except Exception, e: 28 print str(e) 29 return False 30 if __name__ == '__main__': 31 if send_mail(mailto_list,"hello","hello world!"): 32 print "发送成功" 33 else: 34 print "发送失败"
1 # -*- coding: utf-8 -*- 2 ''' 3 发送html文本邮件 4 http://www.cnblogs.com/liu-ke 5 ''' 6 import smtplib 7 from email.mime.text import MIMEText 8 mailto_list=["*****"] 9 mail_host="smtp.***.com" #设置服务器10 mail_user="****" #用户名11 mail_pass="****" #口令 12 mail_postfix="***.com" #发件箱的后缀13 14 def send_mail(to_list,sub,content): #to_list:收件人;sub:主题;content:邮件内容15 me="hello"+"<"+mail_user+"@"+mail_postfix+">" #这里的hello可以任意设置,收到信后,将按照设置显示16 msg = MIMEText(content,_subtype='html',_charset='gb2312') #创建一个实例,这里设置为html格式邮件17 msg['Subject'] = sub #设置主题18 msg['From'] = me 19 msg['To'] = ";".join(to_list) 20 try: 21 s = smtplib.SMTP() 22 s.connect(mail_host) #连接smtp服务器23 s.login(mail_user,mail_pass) #登陆服务器24 s.sendmail(me, to_list, msg.as_string()) #发送邮件25 s.close() 26 return True 27 except Exception, e: 28 print str(e) 29 return False 30 if __name__ == '__main__': 31 if send_mail(mailto_list,"hello","<a href='http://www.cnblogs.com/xiaowuyi'>小五义</a>"): 32 print "发送成功" ,mailto_list 33 else: 34 print "发送失败"
0 0
- 用Python发送邮件
- Python 发送邮件
- python 邮件发送
- 使用PYTHON发送邮件
- python邮件发送
- python发送邮件程序
- python: 发送邮件
- python发送邮件
- python smtp发送邮件
- python 发送邮件实例
- python发送各类邮件
- 用Python发送邮件
- 用Python发送邮件
- python 发送邮件实例
- Python发送邮件测试
- python发送邮件
- python发送邮件
- python发送邮件
- android自动化之monkeyrunner
- Sublime Text安装Package Control
- sublime text之sublimeCodeIntel 的配置
- 解决SublimeCodeIntel回车换行误打代码
- mysql主从同步安装配置
- python发送邮件
- windows / linux系统中,端口被占用解决方法
- Listener监听器
- 热修复框架Nuwa
- 18 个命令&工具帮你定位 Linux 性能问题
- SparkStreaming之HDFS操作
- Droid@screen:在PC屏幕上显示Android手机屏幕
- poj 3525 Most Distant Point from the Sea(二分+半平面交)
- 分支限界法-最少步数走出迷宫