Home > Article > Backend Development > Python3 implements the function of sending QQ emails (html)_python
This article mainly introduces in detail Python3 to implement the function of sending QQ emails. QQ emails in html format have certain reference value. Friends who are interested in Python3 can refer to this article. , this article shares with you the function of sending QQ emails in Python3: html, for your reference, the specific content is as follows
QQ emails have been successfully sent before. Posted below is a qq email in html format
##
import smtplib from email.mime.text import MIMEText from email.utils import formataddr my_sender = 'xxxxxxx@qq.com' # 发件人邮箱账号 my_pass = 'xxxx' # 发件人邮箱密码(当时申请smtp给的口令) my_user = 'xxxxxx@qq.com' # 收件人邮箱账号,我这边发送给自己r def mail(): ret = True try: mail_msg = """<p>Python 邮件发送测试...</p> <p><a href="http://www.baidu.com" rel="external nofollow" >这是一个链接</a></p>""" msg=MIMEText(mail_msg, 'html', 'utf-8') # msg=MIMEText('<邮件内容>','plain','utf-8') msg['From']=formataddr(["xxxxx", my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 msg['To']=formataddr(["xxxxx", 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("邮件发送失败")
Related recommendations:
Example of implementing Baidu speech recognition function in Python
Python3 implements the function of sending QQ emails (attachments)_python
Use Python language to describe the maximum continuous subsequence and
The above is the detailed content of Python3 implements the function of sending QQ emails (html)_python. For more information, please follow other related articles on the PHP Chinese website!