ACTIONS
  • Home
  • My Actions
  • My Projects
  • My Packages
Postmark -> Send Single Email
Postmark → Send Single Email

Action summary

Postmark -> Send Single Email

Xano

Postmark → Send Single Email

Overview

This function allows you to send a single email using the Postmark API. It requires parameters such as the sender email address, recipient email address, subject, body (in either HTML or plain text format), 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. from_email (text) Required
    • Description: The email address of the sender.
    • Example: noreply@yourdomain.com
  4. to_email (text) Required
    • Description: The email address of the recipient.
    • Example: user@example.com
  5. subject (text) Required
    • Description: The subject line of the email.
    • Example: Welcome to Our Service
  6. html_body (text) Optional
    • Description: The HTML content of the email message. If provided, it takes precedence over text_body.
    • Example: <h1>Hello, John!</h1><p>Thank you for signing up.</p>
  7. text_body (text) Optional
    • Description: The plain text content of the email message. If provided and html_body is not, it will be used.
    • Example: Hello, John! Thank you for signing up.

Function Stack

1. Create Variable

  • Create Variable: api_url
    • Purpose: Constructs the API URL for sending single emails.

2. Create Variable

  • Create Variable: api_token
    • Purpose: Stores the Postmark API token.

3. Precondition Logic

  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.
    • Purpose: Ensures recipient email address is formatted correctly.
  4. Precondition: to_email should not exceed 50 email addresses.
    • Purpose: Limits the number of recipients to avoid batch size issues.
  5. Precondition: Either text_body or html_body (or both) are provided.
    • Purpose: Ensures that at least one form of email content is available.
  6. Precondition: html_body is a valid HTML format.
    • Purpose: Ensures that if HTML is provided, it is well-formed.

4. API Request

  • API Request to: https://api.postmarkapp.com/email
    • Purpose: Sends a POST request to the api_url with the following payload:
{
  "from_email": "noreply@yourdomain.com",
  "to_email": "user@example.com",
  "subject": "Welcome to Our Service",
  "html_body": "<h1>Hello, John!</h1><p>Thank you for signing up.</p>", // Optional
  "text_body": "Hello, John! Thank you for signing up." // Optional
}

5. Create Variable

  • Create Variable: postmark_response
    • Purpose: Stores the response from the Postmark API.

6. Create Variable

  • Create Variable: response
    • Purpose: Creates a response object containing the result from the Postmark API.

7. Conditional Check

  • Conditional: Checks if the response status is 200 and the error code is 0.
    • If True: Updates the response object to indicate success.
    • If False: Updates the response object to indicate an error.

Response

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

Success Response

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

Error Response

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

Example

Input

{
  "from_email": "noreply@yourdomain.com",
  "to_email": "user@example.com",
  "subject": "Welcome to Our Service",
  "html_body": "<h1>Hello, John!</h1><p>Thank you for signing up.</p>",
  "text_body": "Hello, John! Thank you for signing up."
}

Output

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

Version notes

2024-10-09 17:57:27
Current
2024-10-09T12:28:03.000+00:00

Postmark → Send Single Email

Overview

This function allows you to send a single email using the Postmark API. It requires parameters such as the sender email address, recipient email address, subject, body (in either HTML or plain text format), 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. from_email (text) Required
    • Description: The email address of the sender.
    • Example: noreply@yourdomain.com
  4. to_email (text) Required
    • Description: The email address of the recipient.
    • Example: user@example.com
  5. subject (text) Required
    • Description: The subject line of the email.
    • Example: Welcome to Our Service
  6. html_body (text) Optional
    • Description: The HTML content of the email message. If provided, it takes precedence over text_body.
    • Example: <html><body><strong>Hello</strong> dear Postmark user.</body></html>
  7. text_body (text) Optional
    • Description: The plain text content of the email message. If provided and html_body is not, it will be used.
    • Example: Hello, John! Thank you for signing up.

Function Stack

1. Create Variable

  • Create Variable: api_url
    • Purpose: Constructs the API URL for sending single emails.

2. Create Variable

  • Create Variable: api_token
    • Purpose: Stores the Postmark API token.

3. Precondition Logic

  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.
    • Purpose: Ensures recipient email address is formatted correctly.
  4. Precondition: to_email should not exceed 50 email addresses.
    • Purpose: Limits the number of recipients to avoid batch size issues.
  5. Precondition: Either text_body or html_body (or both) are provided.
    • Purpose: Ensures that at least one form of email content is available.
  6. Precondition: html_body is a valid HTML format.
    • Purpose: Ensures that if HTML is provided, it is well-formed.

4. API Request

  • API Request to: https://api.postmarkapp.com/email
    • Purpose: Sends a POST request to the api_url with the following payload:
{
  "from_email": "noreply@yourdomain.com",
  "to_email": "user@example.com",
  "subject": "Welcome to Our Service",
  "html_body": "<html><body><strong>Hello</strong> dear Postmark user.</body></html>", // Optional
  "text_body": "Hello, John! Thank you for signing up." // Optional
}

5. Create Variable

  • Create Variable: postmark_response
    • Purpose: Stores the response from the Postmark API.

6. Create Variable

  • Create Variable: response
    • Purpose: Creates a response object containing the result from the Postmark API.

7. Conditional Check

  • Conditional: Checks if the response status is 200 and the error code is 0.
    • If True: Updates the response object to indicate success.
    • If False: Updates the response object to indicate an error.

Response

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

Success Response

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

Error Response

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

Example

Input

{
  "from_email": "noreply@yourdomain.com",
  "to_email": "user@example.com",
  "subject": "Welcome to Our Service",
  "html_body": "<html><body><strong>Hello</strong> dear Postmark user.</body></html>",
  "text_body": "Hello, John! Thank you for signing up."
}

Output

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