Skip to content

Commit f79b1d9

Browse files
author
tuntun
committed
python发送邮件示例
1 parent edf65fc commit f79b1d9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

sendMail.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import smtplib
2+
from email.mime.text import MIMEText
3+
from email.mime.multipart import MIMEMultipart
4+
5+
SERVER = "smtp.qq.com"
6+
7+
COMMASPACE = ', '
8+
9+
# Create the container (outer) email message.
10+
msg = MIMEMultipart()
11+
msg['Subject'] = 'Our family reunion'
12+
13+
14+
msg['From'] = FROM
15+
msg['To'] = COMMASPACE.join(TO)
16+
17+
text = 'hello,world!'
18+
part1 = MIMEText(text, 'plain')
19+
# part2 = MIMEText(html, 'html')
20+
msg.attach(part1)
21+
msg.preamble = 'Our family reunion'
22+
server = smtplib.SMTP(SERVER)
23+
server.login('[email protected]', 'pwd')
24+
server.sendmail(FROM, TO, msg.as_string())
25+
server.quit()

0 commit comments

Comments
 (0)