QQ邮箱发送邮件是指通过QQ邮箱的SMTP(Simple Mail Transfer Protocol)服务器来发送电子邮件。SMTP是一种用于传输电子邮件的协议,它定义了邮件服务器之间如何交换邮件。
smtp.qq.com
465
(SSL加密)或587
(TLS加密)import smtplib
from email.mime.text import MIMEText
from email.header import Header
# SMTP服务器配置
smtp_server = 'smtp.qq.com'
smtp_port = 465
sender_email = 'your_qq_email@qq.com'
sender_password = 'your_authorization_code' # 使用授权码而非邮箱密码
receiver_email = 'recipient_email@example.com'
# 创建邮件对象
message = MIMEText('这是一封测试邮件', 'plain', 'utf-8')
message['From'] = Header('发件人昵称', 'utf-8')
message['To'] = Header('收件人昵称', 'utf-8')
message['Subject'] = Header('测试邮件主题', 'utf-8')
# 连接SMTP服务器并发送邮件
try:
smtp_obj = smtplib.SMTP_SSL(smtp_server, smtp_port)
smtp_obj.login(sender_email, sender_password)
smtp_obj.sendmail(sender_email, [receiver_email], message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print(f"Error: 无法发送邮件, {e}")
finally:
smtp_obj.quit()
通过以上步骤和注意事项,您可以顺利配置QQ邮箱并通过腾讯云发送邮件。
领取专属 10元无门槛券
手把手带您无忧上云