Python—发送邮件
一、发送纯文本邮件
import smtplib from email.mime.text import MIMEText subject = "标题" # 邮件的主题 content = "测试" # 邮件的内容 sender = "" # 发件人 password = "qnrwndesjxmmijce" # 刚才我们在QQ邮箱里设置的授权密码 receiver = "" # 收件人 message = MIMEText(content, "plain", "utf-8") # 内容,格式,编码格式 message["From"] = sender # 发送邮箱 message["To"] = receiver # 接收邮箱 message["Subject"] = subject # 标题 # message = ‘\n‘.join([‘From: {}‘.format(sender), ‘To: {}‘.format(receiver), ‘Subject: {}‘.format(subject), ‘‘, content]) # smtp = smtplib.SMTP() # 普通的邮件发送形式 smtp = smtplib.SMTP_SSL("smtp.qq.com", 465) # QQ邮箱的SMTP服务器(端口465或587) smtp.set_debuglevel(1) # 用set_debuglevel(1)就可以打印出和SMTP服务器交互的所有信息 smtp.login(sender, password) # 登录SMTP服务器,输入发送邮箱和密码 smtp.sendmail(sender, receiver, message.as_string()) smtp.quit() smtp.close()
相关推荐
zhangwentaohh 2020-09-16
文山羊 2020-08-16
行吟阁 2020-07-04
xiaodaiwang 2020-06-12
JasonYeung 2020-06-07
oXiaoChong 2020-06-01
sunnyhappy0 2020-05-19
airfling 2020-05-19
singer 2020-05-06
winmeanyoung 2020-04-11
wenjs00 2020-03-06
vs00ASPNET 2020-02-19
zhangpan 2020-01-10
huakai 2019-12-29
cbao 2019-12-24
idning 2019-12-21
mrice00 2019-12-20