脚本邮箱监控

# 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()




posted @ 2019-08-24 17:58  wxl106  阅读(253)  评论(0编辑  收藏  举报