发送邮件功能函数

 1 #!/usr/bin/env python
 2 # -*- coding:utf8 -*-
 3 # Author:Dong Ye
 4 
 5 def sendmail():
 6     import smtplib
 7     from email.mime.text import MIMEText
 8     from email.utils import formataddr
 9 
10     msg = MIMEText ('第一次玩邮件测试,骚扰下,请见谅','plain','utf-8')
11     msg['From'] = formataddr(["系统告警",'abobo1984@126.com'])
12     msg['To'] = formataddr(["dongye",'wulicheng@gomeholdings.com'])
13     msg['To'] = formataddr(["dongye",'dongye@gomeholdings.com'])
14     msg['subject'] = "告警邮件"
15 
16     server = smtplib.SMTP("smtp.126.com",25)
17     server.login("abobo1984@126.com",'abiao555')
18     server.sendmail('abobo1984@126.com',['wulicheng@gomeholdings.com','dongye@gomeholdings.com',], msg.as_string())
19     server.quit()
20 sendmail()

 

posted @ 2017-12-14 01:14  风之岚翔  阅读(165)  评论(0编辑  收藏  举报