Python 官方文档:入门教程 => 点击学习
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys reload(sys) from email.MIMEText import MIMEText import smtpli
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
from email.MIMEText import MIMEText
import smtplib
sys.setdefaultencoding('utf-8')
import Socket, fcntl, struct
def send_mail(to_list,sub,content):
mail_host="smtp.163.com"
mail_user="XXXXX@163.com"
mail_pass="XXXXXXX"
mail_postfix="163.com"
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
def get_local_ip(ifname = 'eth0'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))
ret = socket.inet_ntoa(inet[20:24])
return ret
if sys.argv[1]!="master" and sys.argv[1]!="backup" and sys.argv[1]!="fault":
sys.exit()
else:
notify_type = sys.argv[1]
if __name__ == '__main__':
strcontent = get_local_ip()+ " " +notify_type+" State is activated, please make sure the HAProxy service running state!"
mailto_list = ['XXXXX@139.com, ]
for mailto in mailto_list:
send_mail(mailto, "HAProxy State switch alarm", strcontent.encode('utf-8'))
--结束END--
本文标题: python 邮件通知程序
本文链接: https://lsjlt.com/news/189147.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0