使用python代码发送邮件【163邮箱发送实例】

import smtplib
from email.mime.text import MIMEText
# 连接163邮箱服务器
mailserver = "smtp.163.com"
# 163邮箱的端口号
mailPort = 25
# 163邮箱的用户名
mailUsername = "[email protected]"
# 使用163邮箱的授权 密码
mailPasswd = "1qaz2wsx"
# 接收方的邮件地址
# to_mail = "[email protected]"
to_mail = "[email protected]"
# 连接邮箱服务器,
smtpServer = smtplib.SMTP(mailserver,mailPort)
# 登陆邮箱服务器, 注意: 密码是邮箱的授权密码,    登陆前必须先授权
smtpServer.login(mailUsername,mailPasswd)
# 写邮件-发件人,收件人,内容
# 创建MIMEtext(),并设置内容
msg = MIMEText("恭喜您,中奖了,请登陆 http://www.cwl.gov.cn/ 中国福利彩票领取")
# 设置主题内容
msg["Subject"] = "恭喜您,中奖了"
msg["From"] = mailUsername
msg["To"] = to_mail




# 发送邮件
smtpServer.sendmail(mailUsername,to_mail,msg.as_string())
# 关闭连接
smtpServer.close()

猜你喜欢

转载自blog.csdn.net/mjp_erhuo/article/details/80126215