python 邮件报警

import smtplib
from smtplib import SMTP_SSL
from email.mime.text import MIMEText
from email.header import Header
fo = open("/mail/tomcatrizhi/rizhi.txt", "r",encoding='utf-8')         #打开一个文件只读
msg = ''' '''                        #将文件内容存入到msg里
while True:
    line = fo.readline()
    msg += line.strip()+'\n'
    if not line:
        break
fo.close()

mail_host = "smtp.exmail.qq.com"                    #邮箱服务
mail_user = "wangkang@innovationai.cn"             #发件人
mail_pass = "Wk17908"                               #发件人邮箱服务密码
receivers = "hedazhi@innovationai.cn"               #收件人   
message = MIMEText(msg.encode('utf-8'), 'plain', 'utf-8')            #调用msg变量为邮件内容发邮件
subject = u'tomcatWARN以上报警日志'                                       #标题
message['Subject'] = Header(subject, 'utf-8')
try:
        smtpObj = SMTP_SSL(mail_host)
        smtpObj.login(mail_user,mail_pass)
        smtpObj.sendmail(mail_user,  receivers, message.as_string())
        print ("邮件发送成功")
except smtplib.SMTPException:
        print ("Error: 无法发送邮件")
fo.close()

 

 

import smtplib
from smtplib import SMTP_SSL
from email.mime.text import MIMEText
from email.header import Header
fo = open("/mail/tomcatrizhi/rizhi.txt", "r",encoding='utf-8')
msg = ''' '''
while True:
    line = fo.readline()
    msg += line.strip()+'\n'
    if not line:
        break
fo.close()

mail_host = "smtp.exmail.qq.com"
mail_user = "wangkang@innovationai.cn"
mail_pass = "Wk17908"
receivers = "hedazhi@innovationai.cn"
message = MIMEText(msg.encode('utf-8'), 'plain', 'utf-8')
subject = u'tomcatWARN以上报警日志'
message['Subject'] = Header(subject, 'utf-8')
try:
        smtpObj = SMTP_SSL(mail_host)
        smtpObj.login(mail_user,mail_pass)
        smtpObj.sendmail(mail_user,  receivers, message.as_string())
        print ("邮件发送成功")
except smtplib.SMTPException:
        print ("Error: 无法发送邮件")
fo.close()

 

转载于:https://www.cnblogs.com/ywrj/p/9698157.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值