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