How to send emails to QQ mail using Python

Source: Internet
Author: User
This article mainly introduces how to send emails to QQ mail via Python, and involves related skills in sending Python emails, for more information about how to send emails to QQ mail via Python, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:

#-*-Coding: UTF-8-*-# ======================================== ======# import smtplib and MIMEText #========================== ================== from email. mime. text import MIMEText import smtplib #================================== ========## to whom, send it to 2 people here #================================================ ======= mailto_list = ["naughty610@qq.com ", "1034791200@qq.com"] #============================================= ======## set the server, username, password, and mailbox suffix #================================ ========== mail_host = "smtp.qq.com" mail_user = "naughty610" mail_pass = "here is your password" mail_postfix = "qq.com" #==== = ==========================================================#send an email # ========================================================== = def send_mail (to_list, sub, content): ''' to_list: To whom sub: Subject content: content send_mail ("aaa@126.com", "sub", "content ") '''me = mail_user + "<" + mail_user + "@" + mail_postfix + ">" msg = MIMEText (content) msg ['subobject'] = sub msg ['from'] = me msg ['to'] = ";". join (to_list) try: s = smtplib. SMTP () s. connect (mail_host) s. login (mail_user, mail_pass) s. sendmail (me, to_list, msg. as_string () s. close () return True expect t Exception, e: print str (e) return False if _ name _ = '_ main _': if send_mail (mailto_list, "here is subject", "here is content"): print "sent successfully" else: print "failed to send"

I hope this article will help you with Python programming.

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.