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