#!/usr/bin/python
#-*-coding:UTF-8-*-
import smtplib
import time
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
IP = os.popen("ifconfig | grep \"inet addr:.*Bcast.*Mask:.*\" | awk -F \" \" '{print $2}' | awk -F \":\" '{print $2}'").read()
mail_namelist = ["******@qq.com"] #收件人邮箱
mail_user = "1*******8@1139.com" #发件人邮箱
mail_pass = "*******"
mail_subject = "idelivery进程报警"
mail_context = """
<html>
<body>
<p style="color:#f00;font-family:arial;font-size:15px">"故障IP:%s</p>
<p style="color:#f00;font-family:arial;font-size:15px">故障说明: %s delivery意外停止,请注意</p>
</body>
</html>
""" % (IP,IP)
def send_main():
msg = MIMEMultipart()
msg['From'] = mail_user
msg['To'] = ";".join(mail_namelist)
msg['Subject'] = mail_subject
txt = MIMEText(mail_context, 'html', 'utf-8')
msg.attach(txt)
smtp = smtplib.SMTP()
smtp.connect('smtp.139.com:25') #协议及端口
smtp.login(mail_user, mail_pass)
smtp.sendmail(mail_user, mail_namelist, msg.as_string())
smtp.quit()
if __name__ == '__main__':
send_main()