Python's small script for sending messages

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2 ImportSmtplib3  fromEmail.mime.textImportMimetext4 5Mailto_list = ['[email protected]','[email protected]','[email protected]','[email protected]']6Mail_host ="smtp.qq.com"  #setting up the server7Mail_user ="1027179157"  #User name8Mail_pass ="xxxxxxxxx"  #Password9Mail_postfix ="qq.com"  #outgoing outbox suffixTen  One defSend_mail (to_list, Sub, content): Ame ="Hello"+"<"+ Mail_user +"@"+ Mail_postfix +">" -msg = mimetext (content, _subtype='Plain', _charset='gb2312') -msg['Subject'] =Sub themsg[' from'] =Me -msg[' to'] =";". Join (to_list) -     Try: -Server =Smtplib. SMTP () + Server.connect (mail_host) - Server.login (Mail_user, Mail_pass) + Server.sendmail (Me, To_list, msg.as_string ()) A server.close () at         returnTrue -     exceptException as E: -         Print(str (e)) -         returnFalse -  - if __name__=='__main__': in     ifSend_mail (Mailto_list,"Hello","Hello world! "): -         Print("sent successfully") to     Else: +         Print("Send failed")

Python's small script for sending messages

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.