Python: Mail sent by script is marked as spam by Gmail
Asked Answered
C

4

4

We have a python script that sends mails everyday to an xml list of addresses. Those mails are always marked as spam by Gmail. Here's the code:

            email_body =  '<html><body><div style="text-align: center; font-family: serif; font-size: 15px;"><br/><br/>@<br/><br/>' + text_splited[i] + '<br/><br/>@<br/><br/><a href="http://anemailstory.net/"><i>Tr@ces</i></a><br/><br/> - <br/><br/><a href="http://anemailstory.net/unsubscribe.html">unsubscribe</a><br/><br/></div></body></html>'  
#text corresponding to that subcription date    

            # email     
            msg = MIMEMultipart('alternative') #Create Multipart msg (allows html)
            msg['To'] = email.utils.formataddr(('Recipient', '[email protected]'))
            msg['From'] = email.utils.formataddr(('Traces', '[email protected]'))
            msg['Subject'] = 'Tr@ces - Part #' + str((i+2))

            part_html = MIMEText(email_body, 'html')
            msg.attach(part_html)

            server = smtplib.SMTP('localhost')
            server.set_debuglevel(False) # show communication with the server
            try:
                server.sendmail('[email protected]', email_addrs, msg.as_string())
            finally:
                server.quit()

And here's the generated email:

Return-path: <[email protected]>
Envelope-to: [email protected]
Delivery-date: Wed, 25 Apr 2012 23:59:07 -0600
Received: from localhost ([127.0.0.1] helo=host131.hostmonster.com)
    by host131.hostmonster.com with esmtp (Exim 4.76)
    (envelope-from <[email protected]>)
    id 1SNHjO-0006T0-C2; Wed, 25 Apr 2012 23:59:06 -0600
Content-Type: multipart/alternative;
    boundary="===============1468314745133566460=="
MIME-Version: 1.0
To: Recipient <[email protected]>
From: Traces <[email protected]>
Subject: Tr@ces - Part #9
X-Identified-User: {:host131.hostmonster.com:andrecas:host131.hostmonster.com} {sentby:program running on server}

--===============1468314745133566460==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<html><body><div style="text-align: center; font-family: serif; font-size: 15px;"><br/><br/>@<br/><br/><br/>Mail content<br/><br/><br/>@<br/><br/><a href="http://anemailstory.net/"><i>Tr@ces</i></a><br/><br/> - <br/><br/><a href="http://anemailstory.net/unsubscribe.html">unsubscribe</a><br/><br/></div></body></html>
--===============1468314745133566460==--

Do you have any solution for this?

Thanks.

Chryselephantine answered 4/5, 2012 at 8:42 Comment(0)
D
9

You email consists of almost only HTML and a link. That smells like spam.

Suggestions:

  • Send a plaintext email (less likely to be considered spam - and more comfortable for many users)
  • If you use HTML, always include a plaintext version
  • Improve the text-to-links/html ratio.
Dissidence answered 4/5, 2012 at 8:46 Comment(1)
I only included a plain text version as well, and didn't change the content to improve the text-to-links/html ratio. I'm not saying that doesn't work, just that seemingly on my setup, adding a plain text version to the html one fixed the problem I had.Postbellum
B
3

Hum... depends on the signature of the SMTP, which might be close to "spam".

  1. try to change the "noreply.net" thing to a real domain

  2. It also might be that the Servers Hostname *.hostmonster.com is on a spamlist, because of known spam from any of their servers (happens often)

  3. Many other reasons...

    • wrong new lines
    • wrong date / time format
    • E-Mail Client can't handle your mail (wrong format)
  4. Try to use another SMTP server, to see if it is the signature or the server and not your script!

  5. Also try to send Mails with less images / links and even a lot more text!

If it is spam, could you please provide some information about X-Spam-Status, X-Spam-Level, X-Spam-DCC (Header elements). They give the best overview about what's going wrong!

-- Some additional Information about Spam: http://emailium.com/blog/wp-content/uploads/2011/02/Exact-Target-Infographic-Spam_vs_Whitelist-v2.jpg

Behindhand answered 4/5, 2012 at 9:1 Comment(0)
W
1

Also try this help document by Google. If you did everything accordingly, you can contact the Google support.

https://support.google.com/mail/bin/answer.py?hl=en&answer=81126

Wellestablished answered 10/5, 2012 at 12:29 Comment(0)
G
0

If you're using google smtp to send emails, make sure to use your Sender's Name matches with your FirstName and Lastname matches with your google account, for example:

First Name: John Last Name: Doe

in python:

sender_address = [email protected]

message["From"] = f"John Doe{sender_address}"

This took me a lot of error and trial.

Gallardo answered 20/1, 2021 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.