发布时间:2019-09-27 07:06:38编辑:auto阅读(1760)
#163邮箱发送邮件
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
my_sender = 'XXXXX@163.com'
my_pass = 'XXXXX'
my_user = 'XXXX@qq.com'
def mail():
ret = True
try:
mail_msg = "Python 邮件发送测试"
msg = MIMEText(mail_msg, 'html', 'utf-8')
msg['From'] = formataddr(["Rocky", my_sender])
msg['To'] = formataddr(["Amy", my_user])
msg['Subject'] = '邮件主题'
'''
#邮箱 发件服务器 非SSL协议端口 SSL协议端口
#163 smtp .163.com 25 465 / 587
#qq smtp.qq.com 25 465 / 587
'''
server = smtplib.SMTP_SSL("smtp.163.com", 465)
server.login(my_sender, my_pass)
server.sendmail(my_sender, [my_user, ], msg.as_string())
server.quit()
except smtplib.SMTPException:
ret=False
return ret
ret = mail()
if ret:
print("邮件发送成功")
else:
print("邮件发送失败")
上一篇: python3 字符串操作
下一篇: Python3 处理 gb18030 乱
47751
46255
37137
34644
29234
25894
24763
19867
19429
17918
5721°
6325°
5843°
5893°
6994°
5832°
5852°
6366°
6320°
7685°