我正在尝试通过 AWS pinpoint 发送包含附件的电子邮件。要通过电子邮件发送附件,您必须使用“RAW”电子邮件内容。我能找到的关于此的唯一文档是:https ://docs.aws.amazon.com/pinpoint-email/latest/APIReference/API_RawMessage.html ,但它缺少很多东西(比如,需要什么标题?)
当我使用“简单”内容发送电子邮件时,它工作正常:
emailInput := &pinpointemail.SendEmailInput{
Destination: &pinpointemail.Destination{
ToAddresses: []*string{&address},
},
FromEmailAddress: &sender,
Content: &pinpointemail.EmailContent{
Simple: &pinpointemail.Message{
Body: &pinpointemail.Body{
Html: &pinpointemail.Content{
Charset: &charset,
Data: &emailHTML,
},
Text: &pinpointemail.Content{
Charset: &charset,
Data: &emailText,
},
},
Subject: &pinpointemail.Content{
Charset: &charset,
Data: &emailSubject,
},
},
}
因为我想添加附件,所以我必须使用“RAW”内容类型。我编写了一个生成电子邮件内容的函数,基于:https ://gist.github.com/douglasmakey/90753ecf37ac10c25873825097f46300 :
func generateRawEmailContent(subject, to, from, HTMLBody string, attachments *[]EmailAttachment) []byte {
buf := bytes.NewBuffer(nil)
buf.WriteString(fmt.Sprintf("Subject: %s\n", subject))
buf.WriteString(fmt.Sprintf("To: %s\n", to))
buf.WriteString(fmt.Sprintf("From: %s\n\n", from))
buf.WriteString("MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n")
buf.WriteString(HTMLBody)
writer := multipart.NewWriter(buf)
boundary := writer.Boundary()
buf.WriteString(fmt.Sprintf("Content-Type: multipart/mixed; boundary=%s\n", boundary))
buf.WriteString(fmt.Sprintf("--%s\n", boundary))
}
}
开满天机
慕尼黑的夜晚无繁华
相关分类