python邮箱验证
发布时间: 2023-09-26 01:35:13
Ⅰ python smtp邮件发送失败怎么办
以下代码调试通过:
#coding:utf-8
importsmtplib
fromemail.mime.textimportMIMEText
fromemail.headerimportHeader
sender='[email protected]'
receiver='[email protected]'
subject='pythonemailtest'
smtpserver='smtp.139.com'
username='[email protected]'
password='xxxxxx'
msg=MIMEText('你好','text','utf-8')#中文需参数‘utf-8',单字节字符不需要
msg['Subject']=Header(subject,'utf-8')
smtp=smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username,password)
smtp.sendmail(sender,receiver,msg.as_string())
smtp.quit()
运行效果:
热点内容