Using templates in AWS SES to send email with attachments

Viewed 3005

I'm trying to use email templates to personalize the email which I send by passing the data to already created templates through a JSON string. Even though I'm able to send a raw email by attaching the files, I want a way through which I can send email attachments in the email while using email templates in SES.

2 Answers

As per my RND there is no way to send an email using SES template along with attachment, But yes we can do something like this.

  1. Grab template from SES using the code below then we can replace the token and then we use these in SendRawEmail email along with the attachements.

     AmazonSimpleEmailService emailSendClient = 
      AmazonSimpleEmailServiceClient.builder()
             .withRegion(Regions.AP_SOUTH_1).build();
     String templateName = "MyTemplate";
     GetTemplateRequest getTemplateRequest = new GetTemplateRequest();
     getTemplateRequest.setTemplateName(templateName);
     GetTemplateResult temp = emailSendClient.getTemplate(getTemplateRequest);
     String htmlpart = temp.getTemplate().getHtmlPart();
    

There is no option for sending the templated email with attachments. On the other hand, SendRawEmail requires you to build your own MIME formatted email message which is far from being easy. you can use nodemailer with AWS SES to accomplish this. follow this link

Related