ACTIONS
  • Home
  • My Actions
  • My Projects
  • My Packages
Postmark -> Send Batch Emails
Postmark → Send Batch Emails

Action summary

Postmark -> Send Batch Emails

Xano

Postmark → Send Batch Emails

Overview

This function allows you to send a batch of emails using the Postmark API. It requires parameters such as the sender email address, recipient email addresses, subject, body, and optionally a template ID.

Inputs

  1. postmark_base_url (registry|text) Required
    • Description: The base url for calling the Postmark API (e.g., "https://api.postmarkapp.com/").
  2. postmark_server_token (registry|text) Required Sensitive data
    • Description: This is the Postmark Server API Token (e.g., "14g8dce4-7054-47c9-a18a-2107e5cf4e41"). This is needed for authentication on endpoints.
  3. message (Object[]) Required Description: An Object of message, each containing the following properties:
    • from_email (text) Required
      • Description: The email address of the sender.
    • to_email (text) Required
      • Description: The email address of the recipient.
    • subject (text) Required
      • Description: The subject line of the email.
    • html_body (text) Optional
      • Description: The HTML content of the email message. If provided, it takes precedence over text_body.
    • text_body (text) Optional
      • Description: The plain text content of the email message. If provided and html_body is not, it will be used.

Function Stack

1. Create Variable: api_url

  • Purpose: Constructs the API URL for sending batch emails.

2. Create Variable: api_token

  • Purpose: Stores the Postmark API token.

3. Create Variable: messages_payload

  • Purpose: Initializes an empty array to store the Postmark formatted messages.

4. Precondition

  1. Precondition: from_email should not exceed 255 characters.
    • Purpose: Ensures the sender email address is not too long.
  2. Precondition: from_email is a valid email format.
    • Purpose: Ensures the sender email address is formatted correctly.
  3. Precondition: to_email is a valid email format and allows comma-separated values.
    • Purpose: Ensures recipient email addresses are formatted correctly and the list is not too long.
  4. Precondition: to_email should not exceed 50 email addresses.
    • Purpose: Limits the number of recipients per batch.
  5. Precondition: text_body or html_body != null
    • Purpose: Either text_body or html_body (or both) are provided.
  6. Precondition: html_body is a valid HTML format
    • Purpose: html_body is a valid HTML format
  7. Convert Message: Postmark Format
    • Purpose: Create a Postmark message object with the required fields, ensuring that to_email is converted to an array if it's a comma-separated list.
  8. Update Variable: Increment message_counter.
    • Purpose: Update message_counter.

5. API Request

  • Sends a POST request to the api_url with the messages_payload as the request body.

6. Create Variable: postmark_response

  • Purpose: Stores the response from the Postmark API.

7 Create Variable: response

  • Purpose: Creates a response object with the result from the Postmark API.

Response

The function returns a success message or an error message depending on the outcome.

Success Response

{
  "To": "user1@example.com",
  "SubmittedAt": "2024-10-07T14:33:15.817Z",
  "MessageID": "message-id-1",
  "ErrorCode": 0,
  "Message": "OK"
},
{
  "To": "user2@example.com",
  "SubmittedAt": "2024-10-07T14:33:15.817Z",
  "MessageID": "message-id-2",
  "ErrorCode": 0,
  "Message": "OK"
}

Error Response

{
  "ErrorCode": 401,
  "Message": "Unauthorized: Missing or incorrect API key."
}

Example

Input

{
  "message": [
    {
      "from_email": "sender@example.com",
      "to_email": "recipient1@example.com,recipient2@example.com",
      "subject": "Welcome to Our Service",
      "html_body": "<h1>Welcome!</h1><p>Thank you for joining our service.</p>",
      "text_body": "Welcome! Thank you for joining our service."
    },
    {
      "from_email": "admin@example.com",
      "to_email": "recipient3@example.com",
      "subject": "Important Update",
      "html_body": "<h1>Update</h1><p>Here’s an important update for you.</p>"
    }
  ]
}

Output

[
  {
    "To": "recipient1@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-1",
    "ErrorCode": 0,
    "Message": "OK"
  },
  {
    "To": "recipient2@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-2",
    "ErrorCode": 0,
    "Message": "OK"
  },
  {
    "To": "recipient3@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-3",
    "ErrorCode": 0,
    "Message": "OK"
  }
]

Version notes

2024-10-09 18:03:53
Current
2024-10-09T12:34:08.000+00:00

Postmark → Send Batch Emails

Overview

This function allows you to send a batch of emails using the Postmark API. It requires parameters such as the sender email address, recipient email addresses, subject, body, and optionally a template ID.

Inputs

  1. postmark_base_url (registry|text) Required
    • Description: The base url for calling the Postmark API (e.g., "https://api.postmarkapp.com/").
  2. postmark_server_token (registry|text) Required Sensitive data
    • Description: This is the Postmark Server API Token (e.g., "14g8dce4-7054-47c9-a18a-2107e5cf4e41"). This is needed for authentication on endpoints.
  3. message (Object[]) Required Description: An Object of message, each containing the following properties:
    • from_email (text) Required
      • Description: The email address of the sender.
    • to_email (text) Required
      • Description: The email address of the recipient.
    • subject (text) Required
      • Description: The subject line of the email.
    • html_body (text) Optional
      • Description: The HTML content of the email message. If provided, it takes precedence over text_body.
    • text_body (text) Optional
      • Description: The plain text content of the email message. If provided and html_body is not, it will be used.

Function Stack

1. Create Variable: api_url

  • Purpose: Constructs the API URL for sending batch emails.

2. Create Variable: api_token

  • Purpose: Stores the Postmark API token.

3. Create Variable: messages_payload

  • Purpose: Initializes an empty array to store the Postmark formatted messages.

4. Precondition

  1. Precondition: from_email should not exceed 255 characters.
    • Purpose: Ensures the sender email address is not too long.
  2. Precondition: from_email is a valid email format.
    • Purpose: Ensures the sender email address is formatted correctly.
  3. Precondition: to_email is a valid email format and allows comma-separated values.
    • Purpose: Ensures recipient email addresses are formatted correctly and the list is not too long.
  4. Precondition: to_email should not exceed 50 email addresses.
    • Purpose: Limits the number of recipients per batch.
  5. Precondition: text_body or html_body != null
    • Purpose: Either text_body or html_body (or both) are provided.
  6. Precondition: html_body is a valid HTML format
    • Purpose: html_body is a valid HTML format
  7. Convert Message: Postmark Format
    • Purpose: Create a Postmark message object with the required fields, ensuring that to_email is converted to an array if it's a comma-separated list.
  8. Update Variable: Increment message_counter.
    • Purpose: Update message_counter.

5. API Request

  • Sends a POST request to the api_url with the messages_payload as the request body.

6. Create Variable: postmark_response

  • Purpose: Stores the response from the Postmark API.

7 Create Variable: response

  • Purpose: Creates a response object with the result from the Postmark API.

Response

The function returns a success message or an error message depending on the outcome.

Success Response

{
  "To": "user1@example.com",
  "SubmittedAt": "2024-10-07T14:33:15.817Z",
  "MessageID": "message-id-1",
  "ErrorCode": 0,
  "Message": "OK"
},
{
  "To": "user2@example.com",
  "SubmittedAt": "2024-10-07T14:33:15.817Z",
  "MessageID": "message-id-2",
  "ErrorCode": 0,
  "Message": "OK"
}

Error Response

{
  "ErrorCode": 401,
  "Message": "Unauthorized: Missing or incorrect API key."
}

Example

Input

{
  "message": [
    {
      "from_email": "sender@example.com",
      "to_email": "recipient1@example.com,recipient2@example.com",
      "subject": "Welcome to Our Service",
      "html_body": "<html><body><strong>Hello</strong> dear Postmark user.</body></html>",
      "text_body": "Welcome! Thank you for joining our service."
    },
    {
      "from_email": "admin@example.com",
      "to_email": "recipient3@example.com",
      "subject": "Important Update",
      "html_body": "<html><body><strong>Hello</strong> dear Postmark user.</body></html>"
    }
  ]
}

Output

[
  {
    "To": "recipient1@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-1",
    "ErrorCode": 0,
    "Message": "OK"
  },
  {
    "To": "recipient2@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-2",
    "ErrorCode": 0,
    "Message": "OK"
  },
  {
    "To": "recipient3@example.com",
    "SubmittedAt": "2024-10-07T14:33:15.817Z",
    "MessageID": "message-id-3",
    "ErrorCode": 0,
    "Message": "OK"
  }
]