我制作了一个简单的程序,可以自动为我发送电子邮件。
但是,当我从riseup.net或protonmail发送电子邮件时,有时会发送失败,因为gmail需要“from”头部信息。
以下是错误信息:
This is the mail system at host mx1.riseup.net.
I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can delete your own text from the attached returned message.
The mail system
: host aspmx.l.google.com[74.125.142.27] said: 550-5.7.1 [198.252.153.129 11] Our system has detected that this message is 550-5.7.1 not RFC 5322 compliant: 550-5.7.1 'From' header is missing. 550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been 550-5.7.1 blocked. Please visit 550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant 550 5.7.1 and review RFC 5322 specifications for more information. 62si8602934pjo.111 - gsmtp (in reply to end of DATA command)
我查了如何添加邮件头部但是出现了问题,无法使其工作。
这是我的代码:
def send_mail():
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, 587) as server:
server.starttls(context=context)
server.login(susername, spassword)
server.sendmail(semail, recipient, message)
print("Email has been sent!")
编辑:当我使用浏览器发送电子邮件时,Riseup会自动添加此标题,但是当我使用Python登录到他们的SMTP服务器时,它不会添加。