python代码实现发送邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python代码实现发送邮件相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = ‘***‘
receiver = ‘***‘
subject = ‘python email test‘
smtpserver = ‘smtp.163.com‘
username = ‘***‘
password = ‘***‘
msg = MIMEText(‘你好‘,‘text‘,‘utf-8‘)#中文需参数‘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()
以上是关于python代码实现发送邮件的主要内容,如果未能解决你的问题,请参考以下文章