Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb56f85

Browse files
author
FlyPython
authored
python email
使用python自动发送邮件
1 parent7df0908 commitfb56f85

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+
importsmtplib
2+
fromemail.mime.textimportMIMEText
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+
exceptsmtplib.SMTPExceptionase:
40+
print('error',e)#打印错误

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp