在使用Go语言的应用引擎中,如何包含电子邮件头部信息?

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

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"}},
}

huangapple
  • 本文由 发表于 2014年8月26日 07:58:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/25496047.html
匿名

发表评论

匿名网友

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

确定