Python implements QQ mailbox to send mail

The examples in this article share the specific code of python to send emails by QQ mailbox for your reference. The specific content is as follows

**1、 Code: **

#! /usr/bin/python
# - *- coding: utf-8-*-import smtplib
from email.mime.text import MIMEText
from email.header import Header
 
mail_host="smtp.qq.com"#The set mail server host must be the server of the sending mailbox and has nothing to do with the receiving mailbox.
mail_user="**************"#QQ mailbox login name
mail_pass="*****************" #The authorization code set when the stmp service is turned on, pay attention! Not a QQ password.
 
sender='[email protected]'#Sender qq mailbox
receivers=['[email protected]']#Recipient qq mailbox
 
message=MIMEText('Test sending python mail','plain','utf-8')
message['From']=Header("beibei",'utf-8') #Set the sender shown in the mail
message['To']=Header("wowo",'utf-8') #Set the recipients shown in the email
 
subject ='python smtp email test'
message['Subject']=Header(subject,'utf-8') #Set theme and format
 
try:
 smtpobj=smtplib.SMTP_SSL(mail_host,465) #If there is a local server, use localhost,Default port 25,Tencent (port 465 or 587)
 smtpobj.set_debuglevel(1)
 smtpobj.login(mail_user,mail_pass)#Log in to the QQ mailbox server
 smtpobj.sendmail(sender,receivers,message.as_string())#send email
 print("Mail sent successfully")
 smtpobj.quit()#drop out
except smtplib.SMTPException as e :print("Error:Unable to send mail")print(e)

2、 Results of the:

3、 Encounter problems:

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 connection refused 535, b'Error:

3.3、 Get authorization code:

The authorization code will be displayed here, write it down.

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python implements QQ mailbox to send mail
Python implements 126 mailboxes to send mail
Python uses the email module to send mail
Python implements SSL sending based on QQ mailbox
Python implements SMTP mail sending
How Python implements the mail function
CentOS 6/7 configure sendEmail to send mail
01. Introduction to Python
How to send mail using sendemail on ubuntu
Introduction to Python
Python implements FTP to upload files in a loop
Python implements Super Mario
Centos 6.4 python 2.6 upgrade to 2.7
Python implements tic-tac-toe game
Centos 6.4 python 2.6 upgrade to 2.7
Python implements tic-tac-toe game
Python implements man-machine gobang
Python implements Tetris game
Python implements image stitching
Python implements minesweeper game
Python implements scanning tools
Python implements threshold regression
Python implements minesweeper games
Python implements electronic dictionary
Python implements guessing game