Python脚本sendmail
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pyodbc
import pprint
import Redis
import urllib
import JSON
import sys
import smtplib
from email.mime.text import MIMEText
reload(sys)
#sys.setdefaultencoding( "utf-8" )
mailto_list=['alarm@ggimg.cn']
mail_host="mail.ggimg.cn" #service
mail_user="zabbix249@ggimg.cn" #user
mail_pass="Yk6VTx/u" #pass
mail_postfix="ggimg.cn" #send maile prefix
def send_mail(to_list,sub,content):
me="hello"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype='plain',_charset='UTF-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
send_mail(mailto_list,"邮件","你好!");
相关文章