python smtplib 发送邮件

来源:互联网 发布:c语言if else嵌套 编辑:程序博客网 时间:2024/05/28 06:08
#coding=utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Header#发送邮箱sender = 'xxxx@163.com'#接收邮箱receiver = 'xxxxx@qq.com'#发送邮件主题subject = 'python email test'#发送邮箱服务器smtpserver = 'smtp.163.com'#发送邮箱用户/密码username = 'xxxxx@163.com'password = 'xxxxxx'msg = MIMEText('<html><h1>你好!</h1></html>','html','utf-8')msg['Subject'] = Header(subject, 'utf-8')smtp = smtplib.SMTP()smtp.connect('smtp.163.com')smtp.login(username, password)smtp.sendmail(sender, receiver, msg.as_string())smtp.quit()

运行的时候 报错 smtplib.SMTPDataError: (554, 'DT:SPM 163 smtp14

最后加上了这两行代码就行了

#coding=utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Header#发送邮箱sender = 'xxxxx@163.com'#接收邮箱receiver = 'xxxxxx@qq.com'#发送邮件主题subject = 'python email test'#发送邮箱服务器smtpserver = 'smtp.163.com'#发送邮箱用户/密码username = 'xxxxx@163.com'password = 'xxxxxx'msg = MIMEText('<html><h1>你好!</h1></html>','html','utf-8')msg['Subject'] = Header(subject, 'utf-8')msg['From'] = 'xxxxx@163.com'msg['To'] = 'xxxxxx@qq.comsmtp = smtplib.SMTP()smtp.connect('smtp.163.com')smtp.login(username, password)smtp.sendmail(sender, receiver, msg.as_string())smtp.quit()


原创粉丝点击