from email.header import Header
from email.mime.text import MIMEText
import smtplib
import os
from_addr=os.environ.get('MAIL_USERNAME')
password=os.environ.get('MAIL_PASSWORD')
print(from_addr)
print(password)
to_addr=os.environ.get('MAIL_USERNAME')
smtp_server='smtp.qq.com'
msg=MIMEText('hello,send by python...','plain','utf-8')
msg['From']=Header('python爱好者','utf-8')
msg['To']=Header('管理员','utf-8')
msg['Subject']=Header('来自SMTP的问候','utf-8')
server=smtplib.SMTP(smtp_server,25)
server.set_debuglevel(1)
server.starttls()
server.login(from_addr,password)
server.sendmail(from_addr,[to_addr],msg.as_string())
server.quit()
smtp模块发送邮件
最新推荐文章于 2023-06-28 18:04:36 发布