from email.mime.text import mimetextfrom email.header import headerfrom Smtplib import smtp_ssldef send_mail (sender_sina= ", pwd=", receiver= ", mail_title=", Mail_ Content= '): # mailbox SMTP Server host_server = ' Smtp.sina.com ' sender_sina_mail = sender_sina+ ' @sina. com ' #ssl登录 smtp = smtp_ssl (host_server) #set_ DebugLevel () is used for debugging. A parameter value of 1 means turn on debug mode with a parameter value of 0 to turn off debug mode 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", "Password", "[email protected]", "title", ' content ')
#!/usr/bin/python#coding:utf-8from email.mime.text import mimetextfrom email.header Import headerfrom smtplib import smtp_sslimport sysdef 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 () is used for debugging. A parameter value of 1 means turn on debug mode with a parameter value of 0 to turn off debug mode 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 ("Send Success") return True except Exception as e : print ("Send failed:", e) return false if __name__== "__main__": #send_ Mail ("hequan2011", "Password", "[email protected]", "title", "Content") send_mail ("hequan2011", "Password", sys.argv[1], sys.argv[2], sys.argv[3])
This article is from the "what-all" blog, please be sure to keep this source http://hequan.blog.51cto.com/5701886/1939844
Python email: Sina Normal Edition | Zabbix version