我的问题很简短,我有一个golang应用程序,我试图使用net / smtp.sendmail发送电子邮件:
这是我要使用的命令
smtp.SendMail(server, auth, **from**, to, msg)
通常没有人将发件人的电子邮件地址传递给来自。无论如何我还可以传递发件人的名字吗?
因此,收件人将收到来自:
的电子邮件Foo Bar <foo@bar.com>
而不是来自
的电子邮件<foo@bar.com>
我在网上检查了官方文档和几十个例子但找不到任何内容。
谢谢。
答案 0 :(得分:2)
您可以将其添加到msg
,例如,扩展您可以使用的official docs示例:
msg := []byte("From: the name <sender@example.org>\r\n" +
"To: recipient@example.net\r\n" +
"Subject: discount Gophers!\r\n" +
"\r\n" +
"This is the email body.\r\n")
请注意:From: the name <sender@example.org>
msg参数应该是RFC 822样式的电子邮件,首先是标题,空白行,然后是邮件正文。 msg的行应该是CRLF终止的。 msg标题通常应包括诸如&#34; From&#34;,&#34; To&#34;,&#34; Subject&#34;和&#34; Cc&#34;等字段。