1. 程式人生 > >python 多用戶發郵件

python 多用戶發郵件

啟動 pytho 匯總 int print name smt utf-8 odin

#!/usr/bin/env python # -*- coding: utf-8 -*- #導入smtplib和MIMEText import smtplib from email.header import Header from email.mime.text import MIMEText def send_server(to_list,sub,content): #設置服務器,用戶名、口令以及郵箱的後綴 mail_host="smtp.163.com" mail_user="[email protected]" mail_pass="1234556" mail_postfix="163.com" me=mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content) msg['Subject'] = sub #msg['From'] = me msg['From'] = '%s<%s>' % (Header('運維團隊', 'utf-8'), '[email protected]') msg['To'] = to_list try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(me, to_list, msg.as_string()) s.close() #print '1' return True except Exception, e: #print '2' print str(e) return False def send_to(): #發到用戶的列表 mail_list = ["buser.com","cuser.com"] for i in range(0, len(mail_list)): if send_server(mail_list[i],"ECS啟動匯總","ECS啟動完畢"): print "發送成功" i=i+1; else: print "發送失敗" i=i+1; if __name__ == '__main__': send_to()


python 多用戶發郵件