码迷,mamicode.com
首页 > 编程语言 > 详细

Python自动群发邮件

时间:2020-04-02 18:02:09      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:art   smtplib   imp   ring   异常   app   自动   nec   ESS   

import smtplib
from email import (header)
from email.mime import (text, application, multipart)
import time

def sender_mail():
    smt_p = smtplib.SMTP()
    smt_p.connect(host=smtp.qq.com, port=25)
    sender, password = 113097485@qq.com, "**************"
    smt_p.login(sender, password)
    receiver_addresses, count_num = [
        guozhennianhua@163.com, xiaoxiazi99@163.com], 1
    for email_address in receiver_addresses:
        try:
            msg = multipart.MIMEMultipart()
            msg[From] = "zhenguo"
            msg[To] = email_address
            msg[subject] = header.Header(这是邮件主题通知, utf-8)
            msg.attach(text.MIMEText(
                这是一封测试邮件,请勿回复本邮件~, plain, utf-8))
            smt_p.sendmail(sender, email_address, msg.as_string())
            time.sleep(10)
            print(第%d次发送给%s % (count_num, email_address))
            count_num = count_num + 1
        except Exception as e:
            print(第%d次给%s发送邮件异常 % (count_num, email_address))
            continue
    smt_p.quit()

sender_mail()


注意: 发送邮箱是qq邮箱,所以要在qq邮箱中设置开启SMTP服务,设置完成时会生成一个授权码,将这个授权码赋值给文中的password变量。

 

Python自动群发邮件

标签:art   smtplib   imp   ring   异常   app   自动   nec   ESS   

原文地址:https://www.cnblogs.com/miaoweiye/p/12620954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!