英文:
Include email header in app engine using go?
问题
谷歌应用引擎文档没有描述如何包含电子邮件头部信息,你要如何做到这一点,即如何更改这个部分?
msg := &mail.Message{
Sender: "Example.com Support support@example.com",
To: []string{"email@bob.com"},
Subject: "Confirm your registration",
Body: fmt.Sprintf(confirmMessage, url),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Couldn't send email: %v", err)
}
英文:
The google app engine documentation doesn't describe how to include an email header, how do you do it, i.e. How do you change this?
msg := &mail.Message{
Sender: "Example.com Support <support@example.com>",
To: []string{"email@bob.com"},
Subject: "Confirm your registration",
Body: fmt.Sprintf(confirmMessage, url),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Couldn't send email: %v", err)
}
答案1
得分: 1
在**appengine/mail
参考文档**中,你可以找到类型Message有一个名为Headers
的字段:
// 额外的邮件头。
// 请参阅 https://developers.google.com/appengine/docs/go/mail/overview
// 了解可接受的头部。
Headers mail.Header
类型mail.Header
可以在**net/mail
**包中找到,只能使用以下头部名称,如上述概述链接中所述:
- In-Reply-To
- List-Id
- List-Unsubscribe
- On-Behalf-Of
- References
- Resent-Date
- Resent-From
- Resent-To
示例:(未经测试)
import netmail "net/mail" // mail已被appengine/mail占用
...
msg := &mail.Message{
Sender: "Example.com Support <support@example.com>",
To: []string{"email@bob.com"},
Subject: "Confirm your registration",
Body: fmt.Sprintf(confirmMessage, url),
Headers: netmail.Header{"In-Reply-To": []string{"123456789"}},
}
英文:
In the appengine/mail
reference you can find that type Message has a field called Headers
:
// Extra mail headers.
// See https://developers.google.com/appengine/docs/go/mail/overview
// for permissible headers.
Headers mail.Header
The type mail.Header
can be found in the net/mail
package, and only the following header names may be used, as described in the above overview link:
- In-Reply-To
- List-Id
- List-Unsubscribe
- On-Behalf-Of
- References
- Resent-Date
- Resent-From
- Resent-To
Example: (untested)
import netmail "net/mail" // mail is already taken by appengine/mail
...
msg := &mail.Message{
Sender: "Example.com Support <support@example.com>",
To: []string{"email@bob.com"},
Subject: "Confirm your registration",
Body: fmt.Sprintf(confirmMessage, url),
Headers: netmail.Header{"In-Reply-To": []string{"123456789"}},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论