将额外信息注入电子邮件的过程是通过SMTP(简单邮件传输协议)完成的。

huangapple go评论84阅读模式
英文:

Extra Info being injected into an email over SMTP

问题

我一直遇到一个非常奇怪的问题。我有一个使用golang编写的服务器,并且我正在使用net/smtp来发送电子邮件。一切都进行得很顺利,直到我们意识到一些额外的信息被注入到电子邮件中,并且雅虎开始忽略我们的邮件。无论如何,我们发送的信息主体如下:

发件人:test@withheld.com
收件人:me@gmail.com
主题:测试
MIME版本:1.0;
内容类型:text/html; charset="UTF-8";
<html>
     <b> 测试 </b>
</html>

然后将其发送到Amazon SES,我们用于发送电子邮件的帐户托管在godaddy上。
当邮件到达时,我使用gmail显示原始消息正文,我得到了这个:

发件人:test@withheld.com
收件人:me@gmail.com
主题:测试
MIME版本:1.0;
内容类型:text/html; charset="UTF-8";

<html>
    <b> 测试 </b>
</html>
日期:2014年10月29日 11:00:56 +0000
消息ID:<[大量数字]@email.amazonses.com>
X-SES-Outgoing:[一些数字]
反馈ID:us-east-1.[数字]=:AmazonSES

所以这4个附加字段被添加到我们的消息正文中,我认为这可能导致我们被标记为垃圾邮件或更糟(雅虎很严厉)。有人知道这4行可能是在哪里添加的吗?肯定是SES,但我对Godaddy的信任要少得多。

(我们的正文中有不同的间距,信息会注入到消息正文的随机位置)

英文:

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=&quot;UTF-8&quot;;
&lt;html&gt;
     &lt;b&gt; Testing &lt;/b&gt;
&lt;/html&gt;

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=&quot;UTF-8&quot;;

&lt;html&gt;
    &lt;b&gt; Testing &lt;/b&gt;
&lt;/html&gt;
Date: Wed, 29 Oct 2014 11:00:56 +0000
Message-ID: &lt;[Lots of Numbers]@email.amazonses.com&gt;
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

得分: 5

你在标题和正文之间缺少一个\r\n。你还缺少日期和消息ID标题。许多垃圾邮件过滤器会将这些缺失视为粗心的垃圾邮件/病毒邮件的迹象。同样,如果没有纯文本备用选项,也会有同样的问题。

Sendgrid或Mandrill可能会默认帮助你解决这些问题。

英文:

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.

答案2

得分: 3

你需要在标题和正文之间添加一个换行符(\r\n)。

此外,如果你想在Go语言中以简单的方式发送电子邮件,你可以使用Gomail(我是作者):

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)
	}
}
英文:

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 (
	&quot;gopkg.in/gomail.v2&quot;
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader(&quot;From&quot;, &quot;test@withheld.com&quot;)
	m.SetHeader(&quot;To&quot;, &quot;me@gmail.com&quot;)
	m.SetHeader(&quot;Subject&quot;, &quot;Testing&quot;)
	m.SetBody(&quot;text/html&quot;, `&lt;html&gt;
     &lt;b&gt; Testing &lt;/b&gt;
&lt;/html&gt;`)

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

huangapple
  • 本文由 发表于 2014年11月3日 08:43:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/26706258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定