Send transactional emails with Postmark

To use the Postmark integration to send transactional emails 1 environment variable is required:

  • POSTMARK_API_KEY - Your Postmark API key is found on the Postmark server API tokens page (https://account.postmarkapp.com/servers/{server-ID}/credentials).

Once you configured this value as an environment variable you can use the two functions to either send plain text emails or pre-built template emails.

To send plain text emails use the following function:

import { sendPlainTextMail } from '@/utils/emails/postmark'

...

await sendPlainTextMail(
  'to-email@test.com',                      // to email address
  'from-email@test.com',                    // from email address - usually an email address from your company
  'Subject of email',                       // email subject
  'Email body - hey this is a test email',  // plain text body of email
  'Email-tag',                              // a way to identify what kind of email it is - e.g. password-reset, checkout-recovery, etc.
)

To send an email using a pre-built Postmark template use the following function:

import { sendTemplateMail } from '@/utils/emails/postmark'

...

await sendTemplateMail(
  'to-email@test.com',                // to email address
  'from-email@test.com',              // from email address - usually an email address from your company
  'email-template-id',                // ID of email template on Postmark - e.g. 29679345
  {                                   // dynamic template data configured in Postmark email templates
    propName1: 'test value',
    propName2: 'another test value',
  },
  'Email-tag',                        // a way to identify what kind of email it is - e.g. password-reset, checkout-recovery, etc.
)
Last updated: