继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

python 多用户发邮件

代码写到手抽筋
关注TA
已关注
手记 294
粉丝 26
获赞 113

#!/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()

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP