码迷,mamicode.com
首页 > 其他好文 > 详细

脚本邮箱监控

时间:2019-08-24 18:42:14      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:__name__   服务器端   content   list()   收件人   脚本   plain   发送   return   

# coding=utf-8
"""
发送邮件
"""
import smtplib
from email.mime.text import MIMEText
from email.header import Header


def send_mail(content=""):
print("send_mail")
smtphost = ‘smtp.exmail.qq.com‘ # smtp服务器
port = 465 # smtp服务器端口
sender = "xxxx@xx.com" # 发件人邮箱
pwd = "xxxxx" # 邮箱密码
receivers = [‘xxx@xx.cn‘, ‘xxx@xxxcn‘, ‘xxxxx@qq.com‘] # 收件人邮箱
subject = "幸运开学季脚本" # 主题
content = content or "***"
msg = MIMEText(content, ‘plain‘, ‘utf-8‘) # 参数分别是邮件内容、文本格式、编码
msg[‘from‘] = Header(sender) # 谁发
msg[‘to‘] = Header("lucky_2019") # 发给谁
msg[‘subject‘] = Header(subject) # 邮件主题
try:
smtpObj = smtplib.SMTP_SSL(smtphost, port) # SSL加密
smtpObj.login(sender, pwd)
smtpObj.sendmail(sender, receivers, msg.as_string())
print("send mail successfully")
except smtplib.SMTPException as e:
print(e)
return 1


def run():
print(‘开始执行‘)
while True:
try:
data_list = award_list()
action_award(data_list)
except Exception as e:
print(e)
msg = f"2019开学季-教师或学生脚本处理报错, 循环退出了 error is {e}"
print(msg)
mail(msg)
continue


if __name__ == "__main__":

run()




脚本邮箱监控

标签:__name__   服务器端   content   list()   收件人   脚本   plain   发送   return   

原文地址:https://www.cnblogs.com/laowang-106/p/11405490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!