0

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("to@email.com")
                .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("sneder@domain.com")
                    .build();

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

    }

Our requirements include support for different templates per language (more of l10n and not just translate i18n). Looking at the documentation I failed to find API to set the locale to the template or a way to define the same template with different locales. Is this supported?

I can always add a locale to the template name e.g.

{
  "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_en_UK"
}

{
  "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_de-DE"
}

And then some add some logic to the code to resolve the template or default to English. I hoped for a more elegant build in solution

Haim Raman
  • 11,508
  • 6
  • 44
  • 70

1 Answers1

0

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.

codeninja.sj
  • 3,452
  • 1
  • 20
  • 37
  • I guess I need to clarify my question (I amended it). I need the template with the same name in different languages (I guess it's more l10n than i18n) as a naive translation sometimes sounds weird. I can always append the locale to the name bu I hoped for a more elegant solution – Haim Raman Aug 01 '23 at 07:45
  • I don't think what you're trying is possible in SES templates. Since it's for L10n, it's better to apply the value transformation logic within the lambda function, rather than trying to achieve them on SES. As mentioned, you can also keep individual templates for each locale, and it will give you more flexibility for customization. – codeninja.sj Aug 01 '23 at 13:27