In this article, we share the example of python to achieve the QQ mailbox to send mail specific code, for your reference, the specific content is as follows
1. Code:
#!/usr/bin/python # -*- coding: utf-8 -*- import smtplib from import MIMEText from import Header mail_host=""The # set mail server host must be the server of the sending mailbox, not related to the receiving mailbox. mail_user="**************"#qq email login name mail_pass="*****************" #The authorization code that was set when the stmp service was turned on! Not QQ password. sender='xxx@'#sender qq email receivers=['xxx@']#Receiver qq mailbox message=MIMEText('Test sending python emails','plain','utf-8') message['From']=Header("beibei",'utf-8') #Set the sender to be shown in the email message['To']=Header("wowo",'utf-8') #Set recipients to be shown in emails subject ='python smtp email test' message['Subject']=Header(subject,'utf-8') # Setting the theme and formatting try: smtpobj=smtplib.SMTP_SSL(mail_host,465) # Localhost if you have a local server, default port 25, Tencent (port 465 or 587) smtpobj.set_debuglevel(1) (mail_user,mail_pass)#Login to QQ mailbox server (sender,receivers,message.as_string())#Send Mail print("Mail sent successfully.") ()#Exit except as e : print("Error:Unable to send mail") print(e)
2. Results of implementation:
3. Problems encountered:
3.1, Port Error SMTP default port is 25, but QQ mailbox is not
smtplib.SMTP_SSL(mail_host,465)
To use SMTP_SSL
3.2, Send rejected connection 535, b'Error.
3.3. Obtain an authorization code:
It will show the authorization code here, write it down.
This is the whole content of this article.