【发布时间】:2016-05-19 20:20:47
【问题描述】:
我基于this post制作了一个使用smtplib发送html电子邮件的小脚本
基本上我想要的是在我们数据库中的某些条件得到满足后自动向我们的订阅者发送一封电子邮件 :
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender = "sender_email@domain.com"
receiver = "receiver_email@domain.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Test email"
msg['From'] = me
msg['To'] = you
# Message body
text = "string message"
html = """\
<html>
<head></head>
<body>
<p>
html message
</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
# Send the message via external SMTP server.
s = smtplib.SMTP('mail.domain.com')
s.sendmail(sender, receiver, msg.as_string())
s.quit()
问题是每当我尝试将脚本运行到我自己以外的任何电子邮件时,我都会收到以下错误:
s.sendmail(me, you, msg.as_string())
File "/usr/lib/python2.7/smtplib.py", line 742, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'other_email@domain.com': (450, 'This mail is temporarily denied')}
编辑:
我检查了我的邮件服务器配置并测试了 3 个不同的地址,其中 2 个我删除了垃圾邮件过滤器,1 个我保留它然后运行脚本。 没有垃圾邮件过滤器的 2 封电子邮件收到了电子邮件,而带有过滤器的一封没有,这就是为什么我认为这是一个垃圾邮件问题,但那一定是我如何设置生成电子邮件的代码,或者我缺少标题?
【问题讨论】:
-
这几乎肯定不是您的代码的问题。电子邮件送达率问题与 Stack Overflow 无关。
-
如果它与我使用的 p 语言或库 smtplib 无关,那么哪个是正确的社区?
-
您可能没有向服务器提供正确的凭据。什么是正确的凭据?我们不知道;请咨询服务提供商。
-
证据不支持“这被视为垃圾邮件被拒绝”的信念。远程 MTA 说的是“走开”而不是“这是垃圾邮件”。