Python Mail Notification Program

Source: Internet
Author: User
Tags haproxy

#!/usr/bin/env python# -*- coding: utf-8 -*-import sysreload (SYS) from email . Mimetext import mimetextimport smtplibsys.setdefaultencoding (' Utf-8 ') import socket,  Fcntl, structdef send_mail (to_list,sub,content):  mail_host= "smtp.163.com"  mail_user= "[ Email protected] " 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 falsedef get_local_ip (ifname =  ' Eth0 '):  s = soCket.socket (Socket.af_inet, socket. SOCK_DGRAM)  inet = fcntl.ioctl (S.fileno (),  0x8915, struct.pack (' 256s ',  ifname[ : []])  ret = socket.inet_ntoa (inet[20:24])  return retif 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 = [' [email protected], ]for mailto in mailto_list:  Send_mail (mailto,  "Haproxy state switch alarm",  strcontent.encode (' Utf-8 '))

See South African ant "High-performance Linux server construction"

This article is from the "Li Weizhong Technology Blog" blog, make sure to keep this source http://liweizhong.blog.51cto.com/1383716/1639917

Python Mail Notification Program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.