Home >Backend Development >Python Tutorial >Python3 implements the function of sending QQ emails (text)_python
This article mainly introduces in detail Python3 to implement the function of sending QQ emails. In terms of text, it has certain reference value. Friends who are interested in Python3 can refer to it
This article shares with you the function of sending QQ emails in Python3: text, for your reference, the specific content is as follows
Note: Before use, you need to set up POP3 and IMAP services in QQ and set up a third-party authorization code
Then hit the x below and fill in the relevant information
import smtplib from email.mime.text import MIMEText from email.utils import formataddr my_sender='xxxx@qq.com' # 发件人邮箱账号 my_pass = 'xxxxxxx' # 发件人邮箱密码(当时申请smtp给的口令) my_user='xxxxxxxx@qq.com' # 收件人邮箱账号,我这边发送给自己r def mail(): ret=True try: msg=MIMEText('<邮件内容>','plain','utf-8') msg['From']=formataddr(["xxxxxx",my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 msg['To']=formataddr(["xxxxxxx",my_user]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 msg['Subject']= '邮件主题' # 邮件的主题,也可以说是标题 server=smtplib.SMTP_SSL("smtp.qq.com", 465) # 发件人邮箱中的SMTP服务器,端口是465 server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱密码 server.sendmail(my_sender,[my_user,],msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 server.quit()# 关闭连接 except Exception:# 如果 try 中的语句没有执行,则会执行下面的 ret=False ret=False return ret ret=mail() if ret: print("邮件发送成功") else: print("邮件发送失败")
The above is the entire article Content, I hope it will be helpful to everyone's learning, and I also hope everyone will support the PHP Chinese website.
Related recommendations:
Introduction to python3’s simple factory mode
A case of Python operating excel files
Examples of implementation of permutation and combination calculation operations in Python
The above is the detailed content of Python3 implements the function of sending QQ emails (text)_python. For more information, please follow other related articles on the PHP Chinese website!