Skip to content

Commit fb56f85

Browse files
author
FlyPython
authored
python email
使用python自动发送邮件
1 parent 7df0908 commit fb56f85

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

sendemail.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import smtplib
2+
from email.mime.text import MIMEText
3+
#设置服务器所需信息
4+
5+
#163邮箱服务器地址
6+
mail_host = 'smtp.163.com'
7+
#163用户名
8+
mail_user = 'flypython***'
9+
#密码(163等邮箱为授权码)
10+
mail_pass = '7******x'
11+
12+
#发送地址
13+
sender = 'flypython.com'
14+
#发送内容为纯文本
15+
message = MIMEText('Hello World ! This is from FlyPython!','plain','utf-8')
16+
#email主题
17+
message['Subject'] = 'FlyPython'
18+
#发送地址
19+
message['From'] = sender
20+
#接受地址
21+
receivers = ['flypython.com@gmail.com']
22+
#接受地址的名称
23+
message['To'] = ['flypython.com@gmail.com']
24+
25+
26+
#登录并发送邮件
27+
try:
28+
smtpObj = smtplib.SMTP()
29+
#连接到服务器
30+
smtpObj.connect(mail_host,25)
31+
#登录到服务器
32+
smtpObj.login(mail_user,mail_pass)
33+
#发送
34+
smtpObj.sendmail(
35+
sender,receivers,message.as_string())
36+
#退出
37+
smtpObj.quit()
38+
print('success')
39+
except smtplib.SMTPException as e:
40+
print('error',e) #打印错误

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy