Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SESv2 SendBulkEmailCommand: Template contains unsupported operations #6657

Closed
3 of 4 tasks
BabyDino opened this issue Nov 13, 2024 · 7 comments
Closed
3 of 4 tasks

SESv2 SendBulkEmailCommand: Template contains unsupported operations #6657

BabyDino opened this issue Nov 13, 2024 · 7 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@BabyDino
Copy link

Checkboxes for prior research

Describe the bug

When using the SendBulkEmailCommand with in-line templates, Handlebars conditional statements are not accepted by the SDK.

{{#if var}}{{var}}{{/if}} throws a BadRequestException:

{
  "status": 400,
  "name": "BadRequestException",
  "message": "Template contains unsupported operations.",
  "details": {}
}

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-sesv2@latest

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.17.0

Reproduction Steps

new SendBulkEmailCommand({
        FromEmailAddress: 'Me <[email protected]>,
        DefaultContent: {
          Template: {
            TemplateContent: {
              Subject: 'Hello world!',
              Text: 'Dear {{#if firstName}} {{firstName}}{{/if}}',
              Html: '<html>Dear {{#if firstName}} {{firstName}}{{/if}}</html>',
            },
            TemplateData: JSON.stringify({ firstName: 'John' }),
          },
        },
        BulkEmailEntries: ...
      });

throws the following exception:

{
  "status": 400,
  "name": "BadRequestException",
  "message": "Template contains unsupported operations.",
  "details": {}
}

Using #if conditional statements is supported, according to the official docs.

Observed Behavior

BadRequestException: Template contains unsupported operations.
    at de_BadRequestExceptionRes (/home/me/dev/project/node_modules/@aws-sdk/client-sesv2/dist-cjs/index.js:3438:21)
    at de_CommandError (/home/me/dev/project/node_modules/@aws-sdk/client-sesv2/dist-cjs/index.js:3358:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/me/dev/project/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async /home/me/dev/project/node_modules/@smithy/core/dist-cjs/index.js:168:18
    at async /home/me/dev/project/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
    at async /home/me/dev/project/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:34:22
    at async Object.email (/home/me/dev/project/dist/src/api/template/controllers/test.js:107:30)

Expected Behavior

Expect the template to send. In case of renderfailures, this is by the configuration set.

Possible Solution

No response

Additional Information/Context

No response

@BabyDino BabyDino added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2024
@zshzbh zshzbh self-assigned this Nov 14, 2024
@RanVaknin RanVaknin assigned RanVaknin and unassigned zshzbh Nov 14, 2024
@RanVaknin
Copy link
Contributor

RanVaknin commented Nov 14, 2024

Hi @BabyDino ,

You are using the wrong API. the docs you linked was for the legacy SES client and not the newer SESv2 client which you are attempting to use in your repro code.

AFAIK SESv2 does not support conditional statements using handlebars. You can use SES's (v1) SendBulkTemplatedEmail API to create a template with a conditional statement and then use it in your emails:

import { SESClient, CreateTemplateCommand, SendBulkTemplatedEmailCommand } from "@aws-sdk/client-ses";

const sesClient = new SESClient({ region: "us-east-1" });

try {
    await sesClient.send(new CreateTemplateCommand({
        Template: {
            TemplateName: "MyTemplate",
            SubjectPart: "Hello world!",
            TextPart: "Dear {{#if firstName}} {{firstName}}{{/if}}",
            HtmlPart: "<html>Dear {{#if firstName}} {{firstName}}{{/if}}</html>"
        }
    }));

    const response = await sesClient.send(new SendBulkTemplatedEmailCommand({
        Source: "[email protected]",
        Template: "MyTemplate",
        Destinations: [{
            Destination: {
                ToAddresses: ["[email protected]"],
            },
            ReplacementTemplateData: JSON.stringify({ firstName: "Joe" })
        }],
        DefaultTemplateData: JSON.stringify({ firstName: "" })
    }));

    console.log(response);
} catch (err) {
    console.error(err);
}

Thanks,
Ran~

@RanVaknin RanVaknin added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 14, 2024
@BabyDino
Copy link
Author

Hi @RanVaknin,

This is the link to the docs regarding inline templates: https://docs.aws.amazon.com/ses/latest/dg/send-personalized-email-api.html#send-personalized-email-api-operations.

The variables work for inline templating on SESv2, but the conditional statements do not. These do work in the example you've provided, but the whole idea of this update was the removal of the requirement for creating a template first (as announced here).

I just ran the 'Inline template code example' using the AWS CLI, and unfortunately I get the same error on SESv2 using the CLI.

So I do agree this is not an issue with this SDK, but rather a higher level API one. Since I am unsure now if this is by design, can you point me to the spot where I can raise another issue?

Many thanks!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 16, 2024
@RanVaknin
Copy link
Contributor

Hi @BabyDino ,

Thanks for the clarification. I agree, this seems like a bug with the service itself.

I have created an internal ticket with the SES service team (ticket ID #P170912725). We will update you when we hear back.
Thanks,
Ran~

@RanVaknin RanVaknin added the service-api This issue is due to a problem in a service API, not the SDK implementation. label Nov 18, 2024
@RanVaknin
Copy link
Contributor

Hi @BabyDino ,

I heard back from the service team:

Inline template – The Template resource is not used, but rather, the subject and body of the email containing variables (placeholders) inline with the written content along with the values for those placeholder variables are provided when calling either the SendEmail or SendBulkEmail v2 API operations.

https://docs.aws.amazon.com/ses/latest/dg/send-personalized-email-api.html

Amazon SES supports only simple substitions when you send email using the SendEmail or SendBulkEmail operations and you provide the full template content in the request.

https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Template.html#SES-Type-Template-TemplateContent

Inline templates do not support conditional statements. I have requested that the service team add some clarifications to their docs about it for future use.

Thanks,
Ran~

@RanVaknin RanVaknin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
@diego-sepulveda-lavin
Copy link

diego-sepulveda-lavin commented Nov 21, 2024

I encountered the same problem, even though I wasn't using conditional statements. After some debugging, I discovered that the issue was caused by using snake_case variables in the inline template.

Initially, I had {{no_reply}}, but after changing it to {{noReply}}, the error disappeared. I also found out that nested properties are not supported either (must use a flat json). The documentation should provide a clearer explanation of this limitation.

@RanVaknin
Copy link
Contributor

Feel free to leave documentation feedback directly with the SES service team here.

Copy link

github-actions bot commented Dec 6, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

4 participants