python 發郵件:sina普通版 | zabbix版本
from email.mime.text import MIMEText from email.header import Header from smtplib import SMTP_SSL def send_mail(sender_sina=‘‘,pwd=‘‘,receiver=‘‘,mail_title=‘‘,mail_content=‘‘): # 郵箱smtp服務器 host_server = ‘smtp.sina.com‘ sender_sina_mail = [email protected] #ssl登錄 smtp = SMTP_SSL(host_server) #set_debuglevel()是用來調試的。參數值為1表示開啟調試模式,參數值為0關閉調試模式 smtp.set_debuglevel(0) smtp.ehlo(host_server) smtp.login(sender_sina, pwd) msg = MIMEText(mail_content, "plain", ‘utf-8‘) msg["Subject"] = Header(mail_title, ‘utf-8‘) msg["From"] = sender_sina_mail msg["To"] = receiver smtp.sendmail(sender_sina_mail, receiver, msg.as_string()) smtp.quit() send_mail("hequan2011","密碼","[email protected]
#!/usr/bin/python #coding:utf-8 from email.mime.text import MIMEText from email.header import Header from smtplib import SMTP_SSL import sys def send_mail(sender_sina=‘‘,pwd=‘‘,receiver=‘‘,mail_title=‘‘,mail_content=‘‘): host_server = ‘smtp.sina.com‘ sender_sina_mail = [email protected]