skip to Main Content

I need to provide email temples in our application.
I was able to create an email template from the cli and generate and send an email from Java SDKv2.
e.g.

template:

{
  "TemplateContent": {
    "Html": "Thank you for reporting a for your email on the <b>{{timestamp}}</b> with subject <b>{{subject}}</b>. ",
    "Subject": "{{subject}}",
    "Text": "Thank you for reporting a for your email on the {{timestamp}} with subject {{subject}}."
  },
  "TemplateName": "thank_you"
}

update the template:

aws sesv2 create-email-template --cli-input-json file:///feedback_thank_you.json

Lambda:

public Void handleRequest(Map<String, Object> stringObjectMap, Context context) {
        Destination destination = Destination.builder()
                .toAddresses("[email protected]")
                .build();
        try {
            Template myTemplate = Template.builder()
                    .templateName("thank_you")
                    .templateData(
                            mapper.writeValueAsString(
                                    Map.of("subject", "Testing templates",
                                            "timestamp", LocalDateTime.now().format(
                                                    DateTimeFormatter.ISO_LOCAL_DATE)
                                    ))
                    )
                    .build();

            EmailContent emailContent = EmailContent.builder()
                    .template(myTemplate)
                    .build();
            SendEmailRequest emailRequest = SendEmailRequest.builder()
                    .destination(destination)
                    .content(emailContent)
                    .fromEmailAddress("[email protected]")
                    .build();

                sesV2ClientBuilder.build().sendEmail(emailRequest);
                System.out.println("email was sent");
           
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

Our requirements include support for different languages (a.k.a i18n).
Looking at the documentation I failed to find API to set the languages to the template or a way to define the same template with different locales.
Is this supported?

2

Answers


  1. I do not know about this being an out of the box feature. However using AWS functionality, you can build this functionality as custom logic.

    For example, you can use Amazon Comprehend to detect what language a request is in (or however you determine what langauge is used). Then if needed, you can use Amazon Translate to translate text into the given language.

    Template myTemplate = Template.builder()
                .templateName(templateName)
                .templateData("{n" +
                  "  "name": "Jason"n," + //Translate this...
                  "  "favoriteanimal": "Cat"n" + //Translate this...
                  "}")
                .build();
    
    Login or Signup to reply.
  2. To support internationalization (i18n), create email templates on SES only for styles. The rest of the i18n text can be passed through the lambda function, as it’s much easier to parse and convert the text within the lambda function.

    However, if you solely prefer to use SES templates, then you have to create a separate SES template for each supported language.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search