Python自动批量发送邮件

Python自动批量发送邮件

  • 1.定义发送邮件函数
  • 2.发送邮件

1.定义发送邮件函数

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr


# 1.定义发送邮件
def send_email(email_addr, send_msg, send_subject):
	 """
    
    :param email_addr: 收件人邮件地址
    :param send_msg: 发送的消息
    :param send_subject: 发送的标题/主题
    :return: 
    """
    # 1.右键内容配置
    msg = MIMEText(send_msg, "html", "utf-8")
    msg['From'] = formataddr(["唐海龙", "[email protected]"])
    msg["Subject"] = send_subject

    # 2.发送邮件
    server = smtplib.SMTP_SSL('smtp.qq.com')
    server.login("[email protected]", "发送的邮箱授权码")
    server.sendmail("[email protected]", email_addr, msg.as_string())
    server.quit()
    print("发送邮件成功")

2.发送邮件

email_list = ["[email protected]", "[email protected]", "[email protected]"]
for i in email_list:
    send_email(i, "测试自动发送邮件", "批量发送")
print("批量发送完成")

你可能感兴趣的:(Python,python,开发语言,后端)