C
C
chrome1232020-10-30 00:06:16
Email
chrome123, 2020-10-30 00:06:16

How to fix these errors when sending an email?

I test my emails for spam using this service.
spamtest. smtp . bz

Also I teach the following errors.
5f9b2cf463041406591713.png
5f9b2cfa27ca1731106805.png
5f9b2d02390f6402443698.png

Tell me how to fix them?

Here is the code for sending emails

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'] = "[email protected]от_кого.ru"
        msg['Reply-To'] = "[email protected]от_кого.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)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-10-30
@MechanID

Judging by the screenshot, the server has an anti-spam system called rspamd, or some kind of fork/analogue of it.
As for errors, these are not errors, these are the results of checks for which spam points are awarded, anti-spam systems do a lot of checks and award points, and the administrator of such a system sets up thresholds, for example, 8 points - mark as spam, 16 points - do not accept at all.
Now about the results of checking your letter:
1 in some header there is a template that is considered bad - without a letter with headers, it is impossible to answer the question - what kind of header is it.
2 mail sending was received without using TLS - you need to check that your script and the sending server uses TLS when sending mail (of course, if the receiving server supports it too)
3 usually a letter that comes from outside has at least two Received headers: in headers - for example
a) Received from my laptop with Outlook - corporate server
b) Received from corporate server - recipient server
And in your letter there is only one such header - this is suspicious.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question