python发送邮件
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站点", "18768196753@139.com"])
13
14 #二.登入邮箱操作,发送邮件
15 server = smtplib.SMTP("smtp.139.com",25)
16 server.login("18768196753@139.com","123213")
17 server.sendmail("18768196753@139.com", email_list, msg.as_string())
18 server.quit()
19
20 emil_list = ["459900477@qq.com","2323449277@qq.com"]#必须是一个列表也可以是一个人
21 content = """
22 你好:
23 我是娄辉
24 """
25 Myemail(emil_list,content,"test")