Jay
Jay

Reputation: 20136

Include email header in app engine using go?

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 <[email protected]>",
            To:      []string{"[email protected]"},
            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)
    }

Upvotes: 1

Views: 63

Answers (1)

ANisus
ANisus

Reputation: 77955

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 <[email protected]>",
        To:      []string{"[email protected]"},
        Subject: "Confirm your registration",
        Body:    fmt.Sprintf(confirmMessage, url),
        Headers:  netmail.Header{"In-Reply-To": []string{"123456789"}},
}

Upvotes: 1

Related Questions