且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

试图通过Python向Google发送电子邮件,电子邮件被拒绝

更新时间:2023-11-04 13:07:28

警告:通过不完整的数据进行猜测

您的电子邮件遭到拒绝为垃圾邮件。确保您的电子邮件符合RFC2822。引用标准



唯一需要的标题字段是起源日期字段,
是发件人地址字段。



在你的情况下,至少添加 From: To:到您的外发电子邮件:

  text ='发件人:%s \转到:%s\ nSubject:%s\\\
\%%s'%(fromaddr,toaddr,subject,msg)



日期:字段。


I'm getting a strange error when I send email through Python using SMTP.

I get an email from Mail Delivery System in my GoDaddy inbox with the error:

[Return Code 550] sid: Xtpe1o00e3l0Tyx01 :: 5.7.1 more information. ye4si18523263pbb.103 - gsmtp

For reference, the script looks like:

import smtplib
server = smtplib.SMTP_SSL('smtpout.secureserver.net', 465)

print("Logging in: ")
server.login("username", "password")

subject = "This is a test email!"
msg = "Sample email message"
text = 'Subject: %s\n\n%s' % (subject, msg)
fromaddr = "fromemail"
toaddr = "toemail"
print("Sending email...")
server.sendmail(fromaddr, toaddr, text)
server.quit()

But I believe my error has nothing to do with the code, but with Google blocking the email.

Warning: Wild guess from incomplete data

Your email is being rejected as spam. Ensure your email is RFC2822-compliant. Quoting the standard:

The only required header fields are the origination date field and the originator address field(s).

In your case, add at least From: and To: to your outgoing email:

text = 'From: %s\nTo: %s\nSubject: %s\n\n%s' % (fromaddr, toaddr, subject, msg)

and confirm that smtplib automatically adds the Date: field.