使用 python 发送邮件

时间:2023-03-08 17:53:53

1.使用python 写发邮箱代码:

def sendmail ():
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
msg = MIMEText('邮件内容', 'plain', 'utf-8')
msg['From'] = formataddr(["发件人名", '发件人地址'])
msg['Subject'] = "主题" server = smtplib.SMTP("发件人邮箱SMTP地址", 25)
server.login("发件人邮箱地址", "发件人邮箱登录密码")
server.sendmail('发件人地址', ['送件人地址', ], msg.as_string())
server.quit()
sendmail()