-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailv05.py
48 lines (31 loc) · 792 Bytes
/
mailv05.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart("alternative")
mail_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>这是一封HTML格式的邮件</h1>
</body>
</html>
"""
msg_html = MIMEText(mail_content,"html","utf-8")
msg.attach(msg_html)
msg_text = MIMEText("I LOVE YOU","plain","utf-8")
msg.attach(msg_text)
from_addr = "1366798119@qq.com"
from_pwd = "hjpovygcxmrshhcj"
to_addr = "1366798119@qq.com"
smtp_srv = "smtp.qq.com"
try:
import smtplib
srv = smtplib.SMTP_SSL(smtp_srv.encode(),465)
srv.login(from_addr,from_pwd)
srv.sendmail(from_addr,[to_addr],msg.as_string())
srv.quit()
except Exception as e:
print(e)