Custom e-mail headers in AWS SES using Go

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

Custom e-mail headers in AWS SES using Go

问题

我想在通过AWS SES发送的出站电子邮件中添加一个References-header。我在go repo和文档中找不到相关内容。

我找到了以下代码:

_, err := svc.SendEmailWithContext(aws.BackgroundContext(), params, func(req *request.Request) {
  req.HTTPRequest.Header.Add("References", referencesID)
})

但据我所知,这只是调整了发送到SES的请求,而不是消息本身。

英文:

I want to add a References-header to the outgoing e-mails I send via AWS SES. I can't find anything referencing this in the go repo, nor the documentation.

I found this:

_, err := svc.SendEmailWithContext(aws.BackgroundContext(), params, func(req *request.Request) {
  req.HTTPRequest.Header.Add("References", referencesID)
})

But AFAIK this just tweaks the outgoing request to SES, not the message itself.

答案1

得分: 3

这是我使用gomail/gomail包和SendRawMessage完成的代码:

svc := ses.New(awsSession)

msg := gomail.NewMessage()
msg.SetHeader("From", config.FromEmail)
msg.SetHeader("To", email)
msg.SetHeader("Subject", subject)
msg.SetHeader("References", referencesID)
msg.SetHeader("In-Reply-To", referencesID)
msg.SetBody("text/html", body)

var emailRaw bytes.Buffer
msg.WriteTo(&emailRaw)

message := &ses.RawMessage{Data: emailRaw.Bytes()}

params := &ses.SendRawEmailInput{
	RawMessage: message,
}

_, err := svc.SendRawEmail(params)
英文:

This is what I ended up doing using the gomail/gomail package and SendRawMessage:

svc := ses.New(awsSession)

msg := gomail.NewMessage()
msg.SetHeader("From", config.FromEmail)
msg.SetHeader("To", email)
msg.SetHeader("Subject", subject)
msg.SetHeader("References", referencesID)
msg.SetHeader("In-Reply-To", referencesID)
msg.SetBody("text/html", body)

var emailRaw bytes.Buffer
msg.WriteTo(&emailRaw)

message := &ses.RawMessage{Data: emailRaw.Bytes()}

params := &ses.SendRawEmailInput{
	RawMessage: message,
}

_, err := svc.SendRawEmail(params)

huangapple
  • 本文由 发表于 2017年8月21日 17:55:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/45794200.html
匿名

发表评论

匿名网友

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

确定