Python3: Send mail using smtplib library and smtp.qq.com mail server

Source: Internet
Author: User

Python3: Send mail using smtplib library and smtp.qq.com mail server

The two places to be aware of when using QQ mail server are:

1. Protocol issues using the 465-Port SSL protocol

2. Password problem occurs smtpauthenticationerror main reason is the password and account information is not correct, here we use QQ server send need to set up a separate password in the mailbox (must), and then open

SMTP/POP3 Services. Then with the QQ Mobile Security Center sweep will give an authorization code, in the code to fill in the password is this authorization code , not the mailbox password!

Example code:

#Python3#Author:lizm#date:2018-07-18 10:00:00#-*-coding:utf-8-*-" "Description: Log in to QQ mailbox to send mail" " fromSmtplibImportSmtp_ssl fromEmail.headerImportHeader fromEmail.mime.textImportMimetext#message DefinitionMail_info = {    " from":"****** @qq. com",    " to":"****** @qq. com",    "hostname":"smtp.qq.com",    "username":"****** @qq. com",    "Password":"*******",    "Mail_subject":"Test",    "Mail_text":"Hello, this was a test email, sended by py",    "mail_encoding":"Utf-8"}if __name__=='__main__':    #using SMTP_SSL is the default use of Port 465SMTP = SMTP_SSL (mail_info["hostname"])    #Set_debuglevel () is used for debugging. A parameter value of 1 means turn on debug mode with a parameter value of 0 to turn off debug modeSmtp.set_debuglevel (1)        #connecting to a serverSmtp.ehlo (mail_info["hostname"])    #Email LoginSmtp.login (mail_info["username"], mail_info["Password"])    #fill in the body contentmsg = Mimetext (mail_info["Mail_text"],"Plain", mail_info["mail_encoding"])    #fill in the message titlemsg["Subject"] = Header (mail_info["Mail_subject"], mail_info["mail_encoding"])    #Sender Email Addressmsg[" from"] = mail_info[" from"]    #Recipient Email Addressmsg[" to"] = mail_info[" to"]    #Send mailSmtp.sendmail (mail_info[" from"], mail_info[" to"], msg.as_string ())#ExitSmtp.quit ()

Python3: Send mail using smtplib library and smtp.qq.com mail server

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.