Email Notifications

Templates

Email notifications in Peak SDK and CLI leverage templates to send structured and customizable messages. These templates use the Handlebars templating language, allowing for dynamic content insertion.

Templates are categorized into two types:

  • Global Templates: These templates are defined at the organization level and can be used across all the email notifications.

  • Custom Templates: These templates are defined at the tenant level and can be used for tenant specific email notifications.

Below is an example of an email notification template using Handlebars syntax:

<html>
    <head>
        <title>Peak Email</title>
    </head>
    <body>
        <h1>Hello {{name}}!</h1>
        <p>Thank you for your interest in {{company}}.</p>
        <p>Best regards,</p>
        <p>Your friends at Peak</p>
    </body>
</html>

This template includes placeholders like {{name}} and {{company}} that will be replaced with actual data when the email is sent.

Note: For assistance with creating or modifying email templates, please contact your tenant admin or Peak support.

Attachments

  • You can send upto 3 attachments per email.

  • In the send-email function, pass the name of the files that you want to send as attachment. If a folder is passed as attachment, a zip is created with its content and that is sent.

  • Only the following file types are supported - .pdf, .docx, .doc, .csv, .txt, .xlsx, .xls, and .zip.

Emails

Sending Email Notifications

To send an email notification, you can provide the payload containing the email configuration. The email configuration includes the email subject, recipients, and the template information.

  1. Using a YAML File

First, create a YAML file to specify the email configuration:

# send_email.yaml

body:
  recipients:
    - person1@peak.ai
    - person2@peak.ai
  cc:
    - person3@peak.ai
  bcc:
    - person4@peak.ai
  subject: Hello from Peak
  templateName: my-email-template
  templateParameters:
    name: John
    company: Peak
attachments:
  - model.txt
  - outputs

To send an email, use the following command:

peak alerts emails send path/to/email.yaml -v path/to/params.yaml

In the above example, the template_parameters would be used to replace the placeholders in the email template with the actual values.

  1. Using Command Line Arguments

Alternatively, send an email directly using command line arguments:

peak alerts emails send --subject <email_subject> --recipients <recipient_1> --recipients <recipient_2> --template-name <template_name> --template-parameters <template_parameters> --attachments model.txt --attachments outputs

The template parameters should be provided as a stringified JSON object.

  1. Using a combination of command line options and YAML:

Combine both methods, where command line arguments override YAML configurations. This method allows you to specify common settings in the YAML file and override them as needed via command line for specific cases.

# send_email.yaml

body:
  recipients:
    - person1@peak.ai
    - person2@peak.ai
  cc:
    - person3@peak.ai
  bcc:
    - person4@peak.ai
  subject: Hello from Peak
  templateName: my-email-template
  templateParameters:
    name: John
    company: Peak
attachments:
  - model.txt
  - outputs
peak alerts emails send path/to/email.yaml --subject "New Subject" --attachments op.txt

In this case, the final email body will look like:

{
    "subject": "New Subject",
    "recipients": ["person1@peak.ai", "person2@peak.ai"],
    "cc": ["person3@peak.ai"],
    "bcc": ["person4@peak.ai"],
    "templateName": "my-email-template",
    "templateParameters": {
        "name": "John Doe",
        "company": "Peak"
    },
    "attachments": ["op.txt"]
}