doubeng9407 2017-04-30 18:18
浏览 413
已采纳

AWS SES SDK发送带有附件的电子邮件

I'm using the official AWS Golang SDK to integrate with SES but can't find any information about how to add some attachments (pdf file represented as []byte in code) to the email.

Could you help me?

The current email sending code looks like this:

sesEmailInput := &ses.SendEmailInput{
    Destination: &ses.Destination{
        ToAddresses: []*string{aws.String("To address")},
    },
    Message: &ses.Message{
        Subject: &ses.Content{
            Data: aws.String("Some text"),
        },
        Body: &ses.Body{
            Html: &ses.Content{
                Data: aws.String("Some Text"),
            },
        },
    },
    Source: aws.String("From address"),
    ReplyToAddresses: []*string{
        aws.String("From address"),
    },
}
if _, err := s.sesSession.SendEmail(sesEmailInput); err != nil {
    return err
}
  • 写回答

1条回答 默认 最新

  • duanjue7745 2017-04-30 18:43
    关注

    To send attachments, use the SendRawEmail API instead of SendEmail. AWS documentation will generally refer to this as constructing a 'raw message' instead of explicitly calling out how to send attachments.

    Example

    From the AWS SDK for Go API Reference, linked below:

    params := &ses.SendRawEmailInput{
        RawMessage: &ses.RawMessage{ // Required
            Data: []byte("PAYLOAD"), // Required
        },
        ConfigurationSetName: aws.String("ConfigurationSetName"),
        Destinations: []*string{
            aws.String("Address"), // Required
            // More values...
        },
        FromArn:       aws.String("AmazonResourceName"),
        ReturnPathArn: aws.String("AmazonResourceName"),
        Source:        aws.String("Address"),
        SourceArn:     aws.String("AmazonResourceName"),
        Tags: []*ses.MessageTag{
            { // Required
                Name:  aws.String("MessageTagName"),  // Required
                Value: aws.String("MessageTagValue"), // Required
            },
            // More values...
        },
    }
    resp, err := svc.SendRawEmail(params)
    

    Further Reading

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站