#!/usr/bin/env python
# -*- coding:UTF-8 -*-
#需要在邮箱处设置开启SMTP服务(第三方客户端发送)
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
def mail():
ret = True
try:
msg = MIMEText(‘测试邮件‘,‘plain‘,‘utf-8‘)
msg[‘From‘] = formataddr([‘18664988372‘,‘[email protected]‘])
msg[‘To‘] = formataddr([‘18664988372‘,‘[email protected]‘])
msg[‘Subject‘] = ‘主题‘
server = smtplib.SMTP("smtp.163.com",25)
server.login("[email protected]",‘wasver60‘) #wasver60是授权第三方登录的密码
server.sendmail("[email protected]",["[email protected]",],msg.as_string())
server.quit()
except Exception:
ret = False
return ret
result = mail()
if result == True:
print ("邮件发送成功")
else:
print ("邮件发送失败")
时间: 2024-10-23 05:59:58