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.