当前位置:   article > 正文

Error: 无法发送邮件(550, b‘The “From“ header is missing or invalid. Please follow RFC5322, RFC2047, RFC822_smtplib.smtpdataerror: (550, b'the "from" header i

smtplib.smtpdataerror: (550, b'the "from" header is missing or invalid. plea

Error: 无法发送邮件(550, b’The “From” header is missing or invalid. Please follow RFC5322, RFC2047, RFC822 standard protocol. https://service.mail.qq.com/detail/124/995.')

import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 第三方 SMTP 服务
mail_host = "smtp.qq.com"  # 设置服务器
mail_user = "1537@qq.com"  # 用户名
mail_pass = "vvvrwjdkqnaujcgf"  # 口令

sender = '1537@qq.com'
receivers = ['14273@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')
message['From'] = Header('ceshi','utf-8')
message['To'] = Header('ces1','utf-8')

subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')

try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mail_host, 25)  # 25 为 SMTP 端口号
    smtpObj.login(`在这里插入代码片`mail_user, mail_pass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    print("邮件发送成功")
except smtplib.SMTPException as e:
    print(f"Error: 无法发邮件{e}")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

需要改的部分
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/432537
推荐阅读
相关标签
  

闽ICP备14008679号