python之邮件提醒

Posted 鸟-叔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之邮件提醒相关的知识,希望对你有一定的参考价值。

list1 = [‘邮箱1‘, ‘邮箱2‘, ‘邮箱3‘]
for username_recv in list1:
mailserver = "smtp.163.com" # 邮箱服务器地址
username_send = ‘发送方邮箱名‘ # 邮箱用户名
password = ‘邮箱名‘ # 邮箱密码:需要使用授权码
# username_recv = #收件人,多个收件人用逗号隔开
mail = MIMEText(‘内容‘, ‘plain‘, ‘utf-8‘)
mail[‘Subject‘] = ‘标题‘
mail[‘From‘] = username_send # 发件人
mail[‘To‘] = username_recv # 收件人;[]里的三个是固定写法
smtp = smtplib.SMTP(mailserver, port=25) # 连接邮箱服务器,smtp的端口号是25
smtp.login(username_send, password) # 登录邮箱
smtp.sendmail(username_send, username_recv, mail.as_string()) # 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp

以上是关于python之邮件提醒的主要内容,如果未能解决你的问题,请参考以下文章

Python学习系列之面向对象

python追踪小说更新并通过邮件提醒

天气提醒邮件服务器(python + scrapy + yagmail)

Python学习程序运行完发送邮件提醒

python--Email提醒

Python自定义任务发邮件提醒