AWS SES SDK Sends Email With Attached Files
I'm using the official AWS Golang SDK to integrate with SES, but can't find any information on how to add some attachments (pdf file, represented as [] byte in the code) via email.
could you help me?
The current sending email 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
}
+3
source to share
1 answer
To send attachments, use the SendRawEmail API instead of SendEmail. AWS documentation generally refers to this as creating a "raw message" rather than explicitly calling the application.
Example
From the AWS SDK for Go API Reference 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)
additional literature
- Amazon API Reference - SendRawEmail
- AWS SDK for Go API Reference - SendRawEmail
- AWS SES Documentation - Sending Raw Email Using Amazon SAS API - This is a good example for email standards and raw message creation (including the section on attachments).
+4
source to share