Тестирую свои письма на спам при помощи такого вот сервиса.
spamtest . smtp . bz
И поучаю следующие ошибки.
Подскажите как их исправить?
Вот код для отправки писем
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import dkim
from email.utils import make_msgid, parsedate_tz, mktime_tz, formatdate
import datetime
import DNS
class senderMail:
def __init__(self, From, To, Title, MessageHtml, MessageText):
self.From = From
self.To = To
self.Domain = To.split("@")[1]
self.MxServer = self.MxServer()
self.Title = Title
self.MessageHtml = MessageHtml
self.MessageText = MessageText
self.sendingMessage()
def MxServer(self):
try:
DNS.DiscoverNameServers()
mx_hosts = DNS.mxlookup(self.Domain)
return tuple(mx_hosts[0]);
except:
return False
def sendingMessage(self):
html = self.MessageHtml
text = self.MessageText
msg = MIMEMultipart('alternative')
msg['Subject'] = self.Title
msg['From'] = self.From
msg['To'] = self.To
msg['Date'] = formatdate()
msg['Message-Id'] = make_msgid(None,"от_кого.ru")
msg['List-Unsubscribe'] = "enable@от_кого.ru"
msg['Reply-To'] = "enable@от_кого.ru"
msg.attach(MIMEText(text, 'plain'))
msg.attach(MIMEText(html, 'html'))
headers = ["To", "From", "Subject", 'Date', 'Message-Id']
with open("ssl/private.pem") as fh:
dkim_private = fh.read()
sig = dkim.sign(
message=msg.as_string().encode("ascii"),
selector=str("mail").encode("ascii"),
domain="от_кого.ru".encode("ascii"),
privkey=dkim_private.encode("ascii"),
include_headers=headers)
msg["DKIM-Signature"] = sig.decode("ascii").lstrip("DKIM-Signature:")
server = smtplib.SMTP(self.MxServer[1])
server.helo("от_кого.ru")
server.sendmail(self.From, self.To, msg.as_string())
server.quit()
html = '<!DOCTYPE html> <html lang="en"> <head> </head> <body > Текст письма</body> </html>'
text = 'Текст письма'
test = senderMail("от_кого@от_кого.ru", "кому@кому.ru", "Заголовок", html, text)