Python mail instance source code

Source: Internet
Author: User

# Import smtplib and MIMEText import smtplib from email. mime. text import MIMEText # define the send list mailto_list = ["root@cnseat.com ", "10118157@qq.com"] # Set the server name, user name, password, and mail suffix mail_host = "smtp.163.com" mail_user = "xx@163.com" mail_pass = "xx" mail_postfix = "163.com" # send mail function def send_mail (to_list, sub, context): ''' to_list: To whom to send sub: topic context: Content send_mail ("xxx@126.com", "sub", "context ") ''' me = mail_user + "<" + mail_user + "@" + mail_postfix + ">" msg = MIMEText (context) msg ['subobject'] = 'python email test' msg ['from'] = sub msg ['to'] = ";". join (to_list) try: send_smtp = smtplib. SMTP () send_smtp.connect (mail_host) send_smtp.login (mail_user, mail_pass) send_smtp.sendmail (me, to_list, msg. as_string () send_smtp.close () print 'success' return True before t (Exception, e): print (str (e) print 'false' send_mail (mailto_list, "test mail ", "Hello ")

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.