邮件

第10课 用 Python 发送邮件

以 qq邮箱为例。准备一个发送邮件的账户和密码以及一个收件邮箱

发送 : 1820672318@qq.com 密码 pengpeng2318

接收:a112121788@163.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import smtplib
from email.mime.text import MIMEText

send_user = '840964310@qq.com'
send_user_password = 'uuwtbwzklbwjbbjh'
receive_user = 'a112121788@163.com'

email_msg = MIMEText("send by python")
email_msg['Subject'] = "python 邮件测试"
email_msg['From'] = send_user
email_msg['To'] = receive_user
try:
 # 设置邮件服务器及端口号
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
# 登录进入邮箱
s.login(send_user, send_user_password)
# 发送邮件
s.sendmail(send_user, receive_user, email_msg.as_string())
print("发送成功")
except e:
print("发送失败")
finally:
s.quit()

视频课程

西瓜视频 https://www.ixigua.com/6851109520190636557/