1 import smtplib
2 from email.mime.text import MIMEText
3 from email.utils import formataddr
4
5 def Myemail(email_list,content,subjects):
6 #一设置邮件内容
7 #1.设置文本内容
8 msg = MIMEText(content,"plain","utf-8")
9 #2.设置邮件主题
10 msg["Subject"] = subjects
11 #3.设置邮件显示的发送人name和addr addr必须是你自己的邮箱地址
12 msg["From"] = formataddr(["LH站点", "[email protected]"])
13
14 #二.登入邮箱操作,发送邮件
15 server = smtplib.SMTP("smtp.139.com",25)
16 server.login("[email protected]","123213")
17 server.sendmail("[email protected]", email_list, msg.as_string())
18 server.quit()
19
20 emil_list = ["[email protected]","[email protected]"]#必须是一个列表也可以是一个人
21 content = """
22 你好:
23 我是娄辉
24 """
25 Myemail(emil_list,content,"test")