版权声明:转载请说明来源,谢谢 https://blog.csdn.net/wsp_1138886114/article/details/88823863
数据库报警邮件
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import re
import time
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def alarm_mail(text):
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
mag = str(now_time) + text
smtp_server = '10.0.100.202'
fromaddr = '[email protected]'
password = 'email_password'
toaddrs = ['[email protected]','[email protected]','[email protected]']
message = MIMEText('数据库:'+str(ip)+',出现异常,敬请关注!时间:'+ str(mag))
message['Subject'] = '据库运行异常状态'
message['From'] = '[email protected]'
message['To'] = ",".join(toaddrs)
try:
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(fromaddr, password)
server.sendmail(fromaddr, toaddrs, message.as_string())
print("email send OK!")
server.quit()
except smtplib.SMTPException as e:
print (e)
if __name__ == '__main__':
text = '传入数据异常'
alarm_mail(text)