邮箱的的smtp邮件发送服务

一、首先在邮箱中配置开启服务

开启授权码,注意qq邮箱使用时及时截图(因为只显示一次,所以要记住)

二、代码如下


import smtplib #登陆邮件服务器,进行邮件发送
from email.mime.text import MIMEText #负责构建邮件格式

subject = "博客"  #标题
content = "xxx"  #内容
sender = "[email protected]"  #发送者
recver = """[email protected]"""  #接收者

password = ""  #授权码

message = MIMEText(content,"plain","utf-8")
message["Subject"] = subject
message["To"] = recver
message["From"] = sender

smtp = smtplib.SMTP_SSL("smtp.163.com",465)
smtp.login(sender,password)
smtp.sendmail(sender,recver.split(",\n"),message.as_string())
smtp.close()

猜你喜欢

转载自blog.csdn.net/qq_40576301/article/details/98063598