Recently, some things need to monitor the alarm sent e-mail, and then found a little material on the internet, wrote a simple script to send a message, mainly using the Python smtplib module, share to everyone to see:
#!/usr/bin/env python #-*-coding:utf-8-*- #import Smtplib and Mimetext ImportSmtplib,sys fromEmail.mime.textImportMimetextdefSend_mail (sub,content):############# #who to send to 1 people heremailto_list=["[email protected]"] ##################### #set the server, user name, password, and suffix of the mailboxMail_host="mail.gyyx.cn"Mail_user="[email protected]"Mail_pass="123456677890"Mail_postfix="gyyx.cn" ###################### " "" To_list: To whom sub: topic Content: Contents send_mail (" [Email protected] "," sub "," Content ")" "Me=mail_user+"<"+mail_user+"@"+mail_postfix+">"msg= Mimetext (content,_charset='GBK') msg['Subject'] =Sub msg[' from'] =Me msg[' to'] =";". Join (mailto_list)Try: S=Smtplib. SMTP () s.connect (mail_host) s.login (Mail_user,mail_pass) S.sendmail (Me, mailto_list, Msg.as_ String ()) S.close () ReturntrueexceptException, E:PrintStr (e) Returnfalseif __name__=='__main__': ifSend_mail (U'This is a Python test message', u'python send mail'): PrintU'sent successfully' Else: PrintU'Send failed'
Transfer from http://wangwei007.blog.51cto.com/68019/978743
Python writes a simple script "go" to send a message