Python writes a simple script "go" to send a message

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.