Python发送邮件(支持中文)

时间:2022-11-07 16:50:02
# -*- coding: utf-8 -*-

from email.header import Header
from email.mime.text import MIMEText
import smtplib def sendmail(subject, content):
sender = '' # 发件人邮箱
password = '' # 发件人邮箱密码
recipients = '' # 收件人邮箱
host = '' # 发件人邮箱主机 msg = MIMEText(content, 'plain', 'utf-8')
msg['From'] = sender
msg['To'] = recipients
msg['Subject'] = Header(subject, 'utf-8').encode() server = smtplib.SMTP(host, 25)
server.login(sender, password)
server.sendmail(sender, [recipients], msg.as_string())
server.quit()