首页 > 代码库 > python 发邮件:sina普通版 | zabbix版本
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 = sender_sina+‘@sina.com‘ #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","密码","hequan2011@sina.com","标题",‘内容‘)
#!/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 = sender_sina+‘@sina.com‘ #ssl登录 smtp = SMTP_SSL(host_server) #set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式 smtp.set_debuglevel(0) smtp.ehlo(host_server) smtp.login(sender_sina, pwd) try: 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() print("发送成功") return True except Exception as e : print("发送失败:",e) return False if __name__=="__main__": #send_mail("hequan2011","密码","hequan2011@sina.com","标题",‘内容‘) send_mail("hequan2011", "密码", sys.argv[1], sys.argv[2], sys.argv[3])
本文出自 “何全” 博客,请务必保留此出处http://hequan.blog.51cto.com/5701886/1939844
python 发邮件:sina普通版 | zabbix版本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。