Extra Info being injected into an email over SMTP

2019-08-05 09:55发布

问题:

I've been having a really strange problem. I have a golang server, and I'm using net/smtp to send out emails. It was going well until we realized some extra information was being injected into emails, and that yahoo started ignoring our emails. Anyways, the information that gets sent out for the body of our info is:

From: test@withheld.com
To: me@gmail.com
Subject: Testing
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";
<html>
     <b> Testing </b>
</html>

That then gets sent to Amazon SES, the account we used to send emails is hosted on godaddy. When the email arrives, and I show the original message body using gmail, I get this:

From: test@withheld.com
To: me@gmail.com
Subject: Testing
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";

<html>
    <b> Testing </b>
</html>
Date: Wed, 29 Oct 2014 11:00:56 +0000
Message-ID: <[Lots of Numbers]@email.amazonses.com>
X-SES-Outgoing: [Some Numbers]
Feedback-ID: us-east-1.[numbers]=:AmazonSES

So those 4 additional fields get tacked on to our message bodies, which I presume would lead to us getting mark as spam or worse (yahoo is brutal.) Does anyone know where these 4 lines could have been added on? Definitely seems like SES, but I trust Godaddy a whole lot less.

(There were points where we had different spacing in our bodies, and the information would then inject into random locations in the message bodies)

回答1:

You need to add a newline (\r\n) between the header and the body.

Also if you want an easy way to send emails in Go you can use Gomail (I'm the author):

package main

import (
    "gopkg.in/gomail.v2"
)

func main() {
    m := gomail.NewMessage()
    m.SetHeader("From", "test@withheld.com")
    m.SetHeader("To", "me@gmail.com")
    m.SetHeader("Subject", "Testing")
    m.SetBody("text/html", `<html>
     <b> Testing </b>
</html>`)

    d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456")
    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }
}


回答2:

You are missing a \r\n between headers and the body. You are also missing a date and a message-ID header. Lots of spam filters will take missing those as a good sign of sloppy spam/virus mail. The same for not having a text-only alternate.

Sendgrid or mandrill might help get these things right by default.