#!/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="w67300444@163.com"
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'), 'w67300444@163.com')
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()
共同学习,写下你的评论
评论加载中...
作者其他优质文章