Let's talk about the authorization code used by Python to send emails via QQ mail.

Source: Internet
Author: User

Let's talk about the authorization code used by Python to send emails via QQ mail.

Qq mail has a new authorization code, which requires a verified mobile phone number to send a text message to the QQ mail server. This authorization code is used for third-party client login, instead of the personal email password used for third-party login.

Two problems encountered during the test:

1. You are prompted to establish an SSL secure connection. So we changed smtplib. SMTP () to smtplib. SMTP_SSL ()

2. After running the code, the program has been running, but there was no response. after about five minutes, I had to stop using ctrl + c. Check the cause to know that the SMTP service port of QQ mail is not the default port 25. Changed to 465.

(The standard port 25 is used for plain text transmission when connecting to the SMTP server. The whole process of sending emails may be eavesdropped. To send emails more securely, You can encrypt the SMTP session. In fact, you must first create an SSL secure connection and then use the SMTP protocol to send emails .)

3. Run the error 535, indicating authorization error. The reason is the authorization code. So I quickly obtained the authorization code for the mailbox.

3. Run the error 535, indicating authorization error. The reason is the authorization code. So I quickly obtained the authorization code for the mailbox.

Finally, the test is finished. The Code is as follows:

# Coding: utf-8import smtplibfrom email. mime. text import MIMETextfrom email. header import Header # third-party SMTP service mail_host = "smtp.qq.com" # Set server mail_user = "****** @ qq.com" # username mail_pass = "******** * "# password, in QQ mail, you can enter an authorization code and use a verified mobile phone to send a text message in the QQ mailbox settings, without spaces sender = ******* qq.com 'receivers = [******** @ qq.com ', ***** @ sina.com.cn'] # receive emails, message = MIMEText ('a test for python', 'plain ', 'utf-8 ') message ['from'] = Header ("ppyy", 'utf-8') message ['to'] = Header ("you", 'utf-8 ') subject = 'my test' message ['subobject'] = Header (Subject, 'utf-8') try: smtpObj = smtplib. SMTP_SSL (mail_host, 465) smtpObj. login (mail_user, mail_pass) smtpObj. sendmail (sender, receivers, message. as_string () smtpObj. quit () print u "email sent successfully" cannot smtplib. SMTPException, e: print e

The above discussion about the authorization code used by Python to send emails via QQ mail is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the help house.

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.