所以我正在使用
smtplib
在 Python 中发送电子邮件,到目前为止,所有这些都因垃圾邮件而被阻止。 https://mail.outboundspamprotection.com 网站上的分数在我尝试发送的所有电子邮件中都在 25
左右。这是我的代码:
message = MIMEMultipart('alternative')
message['Subject'] = subject
message['From'] = self.sender
message['To'] = receiver
message['Date'] = formatdate(localtime=True)
if text:
plain = MIMEText(text, 'plain')
message.attach(plain)
if html:
html = MIMEText(html, 'html')
message.attach(html)
headers = [b'from', b'to', b'subject']
private_key = open('**.pem').read()
signature = dkim.sign(message.as_bytes(), b'key1', b'**', private_key.encode(), include_headers=headers)
signature = signature.decode()
message['DKIM-Signature'] = signature[len("DKIM-Signature: "):]
context = ssl.create_default_context()
with smtplib.SMTP(self.smtp_server, self.port) as server:
server.starttls(context=context)
server.login(self.host_username, self.host_password)
try:
server.sendmail(self.sender, receiver, message.as_string())
finally:
server.quit()
这是我每次都得到的错误。
smtplib.SMTPDataError: (550, b'This message was classified as rSPAM and may not be delivered https://mail.outboundspamprotection.com/mailinfo?id=***&user=***')
我已将 DKIM DNS 条目添加到我的站点。
请记住,我对电子邮件或 SMTP 知之甚少,所以我不需要任何“搜索”评论,因为我不确定要搜索什么才能获得正确的答案。
设置自己的邮件服务器时,您需要做很多事情。快速谷歌搜索给出https://www.linkedin.com/pulse/checklist-mail-server-ravi-rajput
执行列表中的每一项,并使用像 https://mxtoolbox.com/ 这样的工具检查它会让你通过大多数垃圾邮件过滤器。但是,有一些更严格的垃圾邮件过滤器不会信任您的新域,它会转到垃圾邮件。
您还可以使用托管电子邮件服务 - 如 https://www.namecheap.com/hosting/email/ 或 google workspace,因为它会为您处理一些步骤。