调用API发送邮件163邮箱Python

#发邮件的库
import smtplib

#
from email.mime.text import  MIMEText
#SMTP服务器
SMTPSever = "smtp.163.com"
#发邮件的地址
sender = "[email protected]"
#发送这邮箱的密码
passwd = "xxxxxxxx"

#设置发送的内容
message = "liu wang is handsome"
#转化为邮件文本
msg = MIMEText(message)

#主题
msg["Subject"]= "来自帅哥的问候"
#发送者
msg["From"] = sender

#创建SMTP 服务器 连接
mailServer = smtplib.SMTP(SMTPSever,25)
#登陆邮箱
mailServer.login(sender,passwd)
#发送邮件
# while 1:
mailServer.sendmail(sender,["[email protected]"],msg.as_string())
#退出邮箱
mailServer.quit()

163邮箱在设置里需要开通STMP服务

猜你喜欢

转载自blog.csdn.net/qq_41856814/article/details/89397985