Function-generated Email Body for Notification from Automation or Action

Hi there!

I am working on a function that generates the content for an email body, to be used in either a notification effect from an automation or in a notification effect for an action. Platform documentation outlines the process for a “Notification Builder” function, but I wasn’t sure if an automation (or action) function-generated email body could also just take in an HTML string? When I wrote a version of the function below, the function doesn’t populate as an option to select. It is published to master branch and tagged.

export function getExampleEmailBody (object: ObjectType): string {
    return (`  
    <h2>Example header</h2>
    <table style="width:100%;border:1px solid black;border-collapse:collapse;">
      <tr>
        <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 1</th>
        <td style="border:1px solid black;padding:5px;">${object.objectProperty1}</td>
      <tr>
        <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 2</th>
        <td style="border:1px solid black;padding:5px;">${object.objectProperty2}</td>
      </tr>
    </table>
        `);
}

Hi @kelseylt , only functions that output the Notification type (docs) can be used. However, you can use HTML as the content of the email notification, e.g.:

@Function()
public exampleHtmlNotification(object: ObjectType): Notification {
    const emailBody = `
        <h2>Example header</h2>
        <table style="width:100%;border:1px solid black;border-collapse:collapse;">
          <tr>
            <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 1</th>
            <td style="border:1px solid black;padding:5px;">${object.objectProperty1}</td>
          <tr>
            <th style="border:1px solid black;padding:5px;text-align:right;">Object Property 2</th>
            <td style="border:1px solid black;padding:5px;">${object.objectProperty2}</td>
          </tr>
        </table>
    `;

    return Notification.builder()
        .shortNotification(ShortNotification.builder()
            .heading("Notification heading")
            .content("Notification content")
            .build())
        .emailNotificationContent(EmailNotificationContent.builder()
            .subject("Email subject")
            .body(emailBody)
            .build())
        .build();
}
3 Likes