英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论