### Node.js Express Server Setup with Postmark Source: https://postmarkapp.com/developer/integration/ai-prompts Install necessary packages and initialize an Express server with the Postmark client. Ensure your Postmark Server API token is set in your environment variables. ```bash npm install postmark dotenv express ``` ```javascript import express from 'express'; import { ServerClient } from 'postmark'; import dotenv from 'dotenv'; dotenv.config(); const app = express(); app.use(express.json()); // Initialize Postmark client const client = new ServerClient(process.env.POSTMARK_SERVER_TOKEN); ``` -------------------------------- ### Install Dependencies Source: https://postmarkapp.com/developer/integration/ai-prompts Install the necessary libraries for Better Auth and Postmark integration. ```bash npm install better-auth postmark ``` -------------------------------- ### Install Postmark Python SDK Source: https://postmarkapp.com/developer/integration/official-libraries Install the postmark-python library from PyPI. This SDK is fully asynchronous. ```bash pip install postmark-python ``` -------------------------------- ### Install Postmark CLI Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark Command Line Interface globally using npm. ```bash npm i postmark-cli -g ``` -------------------------------- ### Install Postmark Node.js Package with npm Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark Node.js library using npm. ```bash npm install postmark --save ``` -------------------------------- ### Install Postmark PHP Library with Composer Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark PHP library using Composer. ```bash composer require wildbit/postmark-php ``` -------------------------------- ### Example Server Response Source: https://postmarkapp.com/developer/api/servers-api This is an example JSON response when successfully retrieving server details. ```json HTTP/1.1 200 OK Content-Type: application/json { "ID": 1, "Name": "Staging Testing", "ApiTokens": [ "server token" ], "Color": "red", "SmtpApiActivated": true, "RawEmailEnabled": false, "DeliveryType": "Live", "ServerLink": "https://postmarkapp.com/servers/1/streams", "InboundAddress": "yourhash@inbound.postmarkapp.com", "InboundHookUrl": "https://hooks.example.com/inbound", "BounceHookUrl": "https://hooks.example.com/bounce", "OpenHookUrl": "https://hooks.example.com/open", "DeliveryHookUrl": "https://hooks.example.com/delivery", "PostFirstOpenOnly": false, "InboundDomain": "", "InboundHash": "yourhash", "InboundSpamThreshold": 0, "TrackOpens": false, "TrackLinks": "None", "IncludeBounceContentInHook": true, "ClickHookUrl": "https://hooks.example.com/click", "EnableSmtpApiErrorHooks": false } ``` -------------------------------- ### Example Response for Message Opens Source: https://postmarkapp.com/developer/api/messages-api This is an example of a successful response when retrieving message opens. ```json { "TotalCount": 1, "Opens": [ { "RecordType": "Open", "Client": { "Name": "Chrome 34.0.1847.131", "Company": "Google Inc.", "Family": "Chrome" }, "OS": { "Name": "OS X 10.7 Lion", "Company": "Apple Computer, Inc.", "Family": "OS X" }, "Platform": "WebMail", "UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36", "Geo": { "CountryISOCode": "RS", "Country": "Serbia", "RegionISOCode": "VO", "Region": "Autonomna Pokrajina Vojvodina", "City": "Novi Sad", "Zip": "21000", "Coords": "45.2517,19.8369", "IP": "188.2.95.4" }, "MessageID": "927e56d4-dc66-4070-bbf0-1db76c2ae14b", "MessageStream": "outbound", "ReceivedAt": "2014-04-30T05:04:23.8768746-04:00", "Tag": "welcome-user", "Recipient": "john.doe@yahoo.com" } ] } ``` -------------------------------- ### AI Prompt for Better Auth and Postmark Integration Source: https://postmarkapp.com/developer/integration/ai-prompts This prompt guides an AI in setting up Postmark with Better Auth for authentication emails. It covers package installation, configuration, email verification, password reset flows, email template design, client-side integration, and best practices, specifying a Next.js with TypeScript environment. ```markdown Integrate Postmark with Better Auth for authentication emails. Include: 1. Better Auth setup with Postmark: - Install required packages (better-auth, postmark) - Configure Better Auth with email and password authentication - Set up Postmark as the email provider - Configure environment variables 2. Email verification flow: - Implement sendVerificationEmail function using Postmark - Send verification emails on signup - Handle email verification callback - Optionally auto sign-in after verification - Create verification email template with clear CTA 3. Password reset flow: - Implement sendResetPassword function using Postmark - Trigger password reset from client - Send secure password reset emails via Postmark - Create password reset email template - Handle reset token validation 4. Email templates: - Design mobile-responsive email verification template - Design password reset template - Include security messaging - Use Better Auth's provided URL and token - Brand emails with your company identity 5. Client-side integration: - Set up Better Auth client - Handle signup with email verification - Trigger password reset flow - Handle verification callbacks - Display appropriate user feedback 6. Best practices: - Use environment variables for API tokens - Implement proper error handling - Add rate limiting for email sends - Log authentication events - Test email delivery in development Use Next.js with TypeScript. Show both server-side Better Auth config and client-side React components. ``` -------------------------------- ### Install Postmark Ruby Gem Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark Ruby gem using Bundler. Run bundle install after adding it to your Gemfile. ```ruby gem 'postmark' ``` -------------------------------- ### Install Postmark .NET NuGet Package Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark.NET NuGet package for easy API integration in .NET projects. ```nuget PM> Install-Package Postmark ``` -------------------------------- ### Example Response for Get Template Source: https://postmarkapp.com/developer/api/templates-api This JSON object represents a successfully retrieved template, including its ID, name, content, and associated server information. ```json { "Name": "Onboarding Email", "TemplateId": 1234, "Subject": "Hi there, {{Name}}", "HtmlBody": "Hello dear Postmark user. {{Name}}", "TextBody": "{{Name}} is a {{Occupation}}", "AssociatedServerId": 1, "Active": false, "Alias": "onboarding-v1", "TemplateType": "Standard", "LayoutTemplate": "my-layout" } ``` ```json { "Name": "Receipt Email", "TemplateId": 1235, "Subject": "Receipt for {{ product_name }}", "HtmlBody": "This is a receipt for {{ product_name }}...", "TextBody": "This is a receipt for {{ product_name }}", "AssociatedServerId": 1, "Active": false, "Alias": "receipt-v1", "TemplateType": "Standard", "LayoutTemplate": "null" } ``` -------------------------------- ### Install Grunt Postmark Plugin Source: https://postmarkapp.com/developer/integration/official-libraries Install the Grunt Postmark plugin as an npm package. ```bash npm install grunt-postmark --save ``` -------------------------------- ### Example Server Response Source: https://postmarkapp.com/developer/api/servers-api This is an example of a successful response when retrieving server details. It includes various configuration options for a Postmark server. ```json HTTP/1.1 200 OK Content-Type: application/json { "ID": 1, "Name": "Staging Testing", "ApiTokens": [ "server token" ], "Color": "red", "SmtpApiActivated": true, "RawEmailEnabled": false, "DeliveryType": "Live", "ServerLink": "https://postmarkapp.com/servers/1/streams", "InboundAddress": "yourhash@inbound.postmarkapp.com", "InboundHookUrl": "https://hooks.example.com/inbound", "BounceHookUrl": "https://hooks.example.com/bounce", "OpenHookUrl": "https://hooks.example.com/open", "DeliveryHookUrl": "https://hooks.example.com/delivery", "PostFirstOpenOnly": false, "InboundDomain": "", "InboundHash": "yourhash", "InboundSpamThreshold": 5, "TrackOpens": false, "TrackLinks": "None", "IncludeBounceContentInHook": true, "ClickHookUrl": "https://hooks.example.com/click", "EnableSmtpApiErrorHooks": false } ``` -------------------------------- ### Install Postmark Craft Plugin with Composer Source: https://postmarkapp.com/developer/integration/official-libraries Install the Postmark Craft plugin using Composer. ```bash composer require craftcms/postmark ``` -------------------------------- ### Example Webhook Response Source: https://postmarkapp.com/developer/api/webhooks-api This is an example of a successful response when retrieving webhook details. ```json HTTP/1.1 200 OK Content-Type: application/json { "ID": 1234567, "Url": "https://www.example.com/webhooks", "MessageStream": "outbound", "HttpAuth":{ "Username": "user", "Password": "pass" }, "HttpHeaders":[ { "Name": "name", "Value": "value" } ], "Triggers": { "Open":{ "Enabled": true, "PostFirstOpenOnly": false }, "Click":{ "Enabled": true }, "Delivery":{ "Enabled": true }, "Bounce":{ "Enabled": true, "IncludeContent": false }, "SpamComplaint":{ "Enabled": true, "IncludeContent": false }, "SubscriptionChange": { "Enabled": false } } } ``` -------------------------------- ### Install Postmark Driver for Laravel Source: https://postmarkapp.com/developer/integration/ai-prompts Use Composer to install the official Postmark driver for Laravel. This is the first step in integrating Postmark. ```bash # Install Postmark driver composer require wildbit/laravel-postmark ``` -------------------------------- ### Server API Example Response Source: https://postmarkapp.com/developer/api/server-api This snippet shows an example of a successful response from the Server API, detailing the structure and fields returned for a server configuration. ```APIDOC ## GET /servers/{ID} ### Description Retrieves the details of a specific server configuration. ### Method GET ### Endpoint /servers/{ID} ### Parameters #### Path Parameters - **ID** (integer) - Required - The unique identifier of the server. ### Response #### Success Response (200) - **ID** (integer) - The unique identifier of the server. - **Name** (string) - The name of the server. - **ApiTokens** (array of strings) - A list of API tokens associated with the server. - **Color** (string) - The color associated with the server. - **SmtpApiActivated** (boolean) - Indicates if SMTP API is activated. - **RawEmailEnabled** (boolean) - Indicates if raw email is enabled. - **DeliveryType** (string) - The type of delivery for the server. - **ServerLink** (string) - A link to the server details page. - **InboundAddress** (string) - The inbound email address for the server. - **InboundHookUrl** (string) - The URL for inbound email webhooks. - **BounceHookUrl** (string) - The URL for bounce webhooks. - **OpenHookUrl** (string) - The URL for open tracking webhooks. - **DeliveryHookUrl** (string) - The URL for delivery status webhooks. - **PostFirstOpenOnly** (boolean) - Whether to only post the first open event. - **InboundDomain** (string) - The inbound domain for the server. - **InboundHash** (string) - The inbound hash for the server. - **InboundSpamThreshold** (integer) - The spam threshold for inbound emails. - **TrackOpens** (boolean) - Indicates if opens are tracked. - **TrackOpens** (string) - The tracking opens setting. - **IncludeBounceContentInHook** (boolean) - Whether to include bounce content in webhooks. - **ClickHookUrl** (string) - The URL for click tracking webhooks. - **EnableSmtpApiErrorHooks** (boolean) - Indicates if SMTP API error webhooks are enabled. #### Response Example { "ID": 1, "Name": "Production Testing", "ApiTokens": [ "Server Token" ], "Color": "blue", "SmtpApiActivated": false, "RawEmailEnabled": false, "DeliveryType": "Live", "ServerLink": "https://postmarkapp.com/servers/1/streams", "InboundAddress": "yourhash@inbound.postmarkapp.com", "InboundHookUrl": "https://hooks.example.com/inbound", "BounceHookUrl": "https://hooks.example.com/bounce", "OpenHookUrl": "https://hooks.example.com/open", "DeliveryHookUrl": "https://hooks.example.com/delivery", "PostFirstOpenOnly": false, "InboundDomain": "", "InboundHash": "yourhash", "InboundSpamThreshold": 10, "TrackOpens": false, "TrackOpens": "None", "IncludeBounceContentInHook": true, "ClickHookUrl": "https://hooks.example.com/click", "EnableSmtpApiErrorHooks": true } ``` -------------------------------- ### Install Postmark Plugin in Craft CMS Source: https://postmarkapp.com/developer/integration/official-libraries Tell Craft CMS to install the Postmark plugin after it has been added via Composer. ```bash ./craft install/plugin postmark ``` -------------------------------- ### Get Bulk Email Request Status - Response Example Source: https://postmarkapp.com/developer/api/bulk-email This is an example of a successful response when querying the status of a bulk email request. ```json HTTP/1.1 200 OK Content-Type: application/json { "Id": "dc5e5d98-c073-4c97-8ee5-f897dfd28b47", "SubmittedAt": "2024-07-22T15:39:49.3723691Z", "TotalMessages": 1, "PercentageCompleted": 1, "Status": "Completed", "Subject": "Hello" } ``` -------------------------------- ### Example Response for Outbound Clicks Source: https://postmarkapp.com/developer/api/stats-api This is an example JSON response for a request to get outbound click counts. It shows clicks aggregated by date and overall. ```json HTTP/1.1 200 OK Content-Type: application/json { "Days": [ { "Date": "2014-01-01", "Apple Mail": 1, "Outlook 2010": 1 }, { "Date": "2014-01-02", "Apple Mail": 1, "Outlook 2010": 2 }, { "Date": "2014-01-04", "Apple Mail": 4, "Outlook 2010": 5 } ], "Apple Mail": 6, "Outlook 2010": 8 } ``` -------------------------------- ### Postmark CLI Usage Example Source: https://postmarkapp.com/developer/integration/official-libraries View available commands and options for the Postmark CLI. ```bash $ postmark Commands: postmark email [options] Send an email postmark servers [options] Manage your servers postmark templates [options] Pull and push your templates Options: --version Show version number --help Show help ``` -------------------------------- ### Get Bulk Email Request Status - Curl Example Source: https://postmarkapp.com/developer/api/bulk-email Use this curl command to retrieve the status and details of a specific bulk email request using its ID. ```bash curl "https://api.postmarkapp.com/email/bulk/{bulk-request-id}" -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` -------------------------------- ### List Templates Request Example (curl) Source: https://postmarkapp.com/developer/api/templates-api Demonstrates how to list templates using curl, including query parameters for pagination and filtering by layout template. ```bash curl "https://api.postmarkapp.com/templates?count=100&offset=0&LayoutTemplate=my-layout" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` -------------------------------- ### Get Bounce Dump Request Example (curl) Source: https://postmarkapp.com/developer/api/bounce-api This curl command retrieves the raw dump data for a specific bounce. Replace '{bounceid}' with the bounce's ID and include your server token. ```bash curl "https://api.postmarkapp.com/bounces/{bounceid}/dump" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` -------------------------------- ### Send Welcome Email from Controller Source: https://postmarkapp.com/developer/integration/ai-prompts This snippet shows how to create a user and then queue a welcome email using the Mail facade. Ensure the WelcomeEmail class and User model are correctly set up. ```php // app/Http/Controllers/Auth/RegisterController.php use App\Mail\WelcomeEmail; use Illuminate\Support\Facades\Mail; public function store(Request $request) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', ]); $user = User::create([ 'name' => $validated['name'], 'email' => $validated['email'], 'password' => Hash::make($validated['password']), ]); // Send welcome email in queue Mail::to($user)->queue(new WelcomeEmail($user)); return redirect()->route('home') ->with('success', 'Account created! Check your email.'); } ``` -------------------------------- ### Get Bounce Request Example (curl) Source: https://postmarkapp.com/developer/api/bounce-api Use this curl command to retrieve details for a specific bounce using its ID. Ensure you replace '{bounceid}' with the actual bounce ID and provide your server token. ```bash curl "https://api.postmarkapp.com/bounces/{bounceid}" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` -------------------------------- ### AI Prompt for Node.js/Express Email Notification System Source: https://postmarkapp.com/developer/integration/ai-prompts This prompt guides an AI in building a Postmark-based email notification system for user actions. It covers event system setup, defining notification types, email sending logic, content strategies (templates vs. inline), logging, and user preferences. Use this prompt with your preferred AI chat tool. ```markdown Build an email notification system using Postmark that sends emails based on user actions. Include: 1. Event system setup: - Create an event emitter or use a message queue (like Bull/BullMQ) - Define common user action events (signup, purchase, profile_update, etc.) - Create event handlers that trigger email sends - Handle async email sending to not block user actions 2. Notification email types: - Welcome email on user signup - Order confirmation after purchase - Profile update confirmation - Password changed notification - Account activity alert (new login from unfamiliar device) 3. Email sending logic: - Configure Postmark client - Create reusable email sending function - Pass dynamic user data to emails - Include user preferences (don't send if user opted out) - Handle email send failures gracefully 4. Template or inline content: - Show both approaches: using templates vs. inline HTML - Include personalization with user data - Make emails actionable with clear CTAs - Ensure mobile-responsive HTML 5. Logging and monitoring: - Log all notification events - Track email send success/failure - Store notification history per user - Handle retry logic for failed sends 6. User preferences: - Check notification preferences before sending - Allow users to opt out of certain notification types - Always send critical notifications (security alerts) Use Node.js/Express with TypeScript. Use async/await for all email operations. ``` -------------------------------- ### Create a Server Source: https://postmarkapp.com/developer/user-guide/managing-your-account Programmatically create a new Postmark server. This is useful for automating server setup in different environments. ```python from postmark.core import PostmarkClient postmark = PostmarkClient(account_token='YOUR_ACCOUNT_TOKEN') postmark.servers.create( Name='My New Server', ServerToken='YOUR_SERVER_TOKEN_FOR_NEW_SERVER', ApiTokens=['YOUR_API_TOKEN_FOR_NEW_SERVER'], SmtpServers=['YOUR_SMTP_TOKEN_FOR_NEW_SERVER'], Color='blue', HeddaEnabled=True ) ``` -------------------------------- ### Create a Server Source: https://postmarkapp.com/developer/user-guide/managing-your-account/managing-servers Creates a new server with the specified details. Requires a name and a production flag. ```http POST https://api.postmarkapp.com/v2/servers Content-Type: application/json { "Name": "My New Server", "Production": false } ``` -------------------------------- ### Get a domain’s details Source: https://postmarkapp.com/developer/api/domains-api Gets all the details for a specific domain. ```APIDOC ## GET /domains/{domainid} ### Description Gets all the details for a specific domain. ### Method GET ### Endpoint /domains/{domainid} ### Parameters #### Path Parameters - **domainid** (string) - Required - The ID of the domain to retrieve details for. ### Request Example ```curl curl "https://api.postmarkapp.com/domains/{domainid}" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Account-Token: account token" ``` ``` -------------------------------- ### Set up Client-Side Authentication Source: https://postmarkapp.com/developer/integration/ai-prompts Initializes the authentication client for client-side use. Ensure the NEXT_PUBLIC_APP_URL environment variable is set. ```typescript // lib/auth-client.ts import { createAuthClient } from 'better-auth/react'; export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_APP_URL || 'https://localhost:3000' }); ``` -------------------------------- ### Get sent counts Source: https://postmarkapp.com/developer/api/stats-api Gets a total count of emails you’ve sent out. ```APIDOC ## GET /stats/outbound/sends ### Description Gets a total count of emails you’ve sent out. ### Method GET ### Endpoint /stats/outbound/sends ### Parameters #### Query Parameters - **tag** (string) - Optional - Filter by tag - **fromdate** (string) - Optional - Filter stats starting from the date specified (inclusive). e.g. 2014-01-01 - **todate** (string) - Optional - Filter stats up to the date specified (inclusive). e.g. 2014-02-01 - **messagestream** (string) - Optional - Filter by message stream. If not provided, the response will include stats for all streams in the server. ### Request Example ``` curl "https://api.postmarkapp.com/stats/outbound/sends?fromdate=2014-01-01&todate=2014-02-01" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` ### Response #### Success Response (200) - **Days** (array) - List of objects that each represent sent counts by date. - **Date** (string) - The date of the sent count. - **Sent** (integer) - Number of sent emails. - **Sent** (integer) - Total number of sent emails. #### Response Example ```json { "Days": [ { "Date": "2014-01-01", "Sent": 140 }, { "Date": "2014-01-02", "Sent": 160 }, { "Date": "2014-01-04", "Sent": 50 }, { "Date": "2014-01-05", "Sent": 115 } ], "Sent": 615 } ``` ``` -------------------------------- ### Example Webhook Deletion Response Source: https://postmarkapp.com/developer/api/webhooks-api This is an example of a successful response after a webhook has been deleted. ```json HTTP/1.1 200 OK Content-Type: application/json { "ErrorCode": 0, "Message": "Webhook 1234 removed." } ``` -------------------------------- ### Set up Event System with Postmark Client Source: https://postmarkapp.com/developer/integration/ai-prompts Initialize the Postmark client and an event emitter. Define event types for user actions and emit events from your API endpoints without blocking the response. ```typescript import EventEmitter from 'events'; import { ServerClient } from 'postmark'; const client = new ServerClient(process.env.POSTMARK_SERVER_TOKEN); const eventBus = new EventEmitter(); // Define event types enum UserEvent { SIGNUP = 'user.signup', PURCHASE = 'user.purchase', PROFILE_UPDATE = 'user.profile_update', PASSWORD_CHANGE = 'user.password_change', NEW_LOGIN = 'user.new_login' } // Emit events from your application app.post('/api/users/signup', async (req, res) => { const user = await createUser(req.body); // Emit event without blocking response eventBus.emit(UserEvent.SIGNUP, { user }); res.json({ user }); }); ``` -------------------------------- ### Create a server Source: https://postmarkapp.com/developer/api/servers-api Creates a new server with the specified details. ```APIDOC ## POST /servers ### Description Creates a new server with the specified details. ### Method POST ### Endpoint /servers ``` -------------------------------- ### Create a server Source: https://postmarkapp.com/developer/api/servers-api Creates a new server for your Postmark account. Requires account-level privileges and an account token. You can specify the server's name and color. ```APIDOC ## POST /servers ### Description Creates a new server for your Postmark account. ### Method POST ### Endpoint /servers ### Parameters #### Request Headers - **Content-Type** (string) - Required - application/json - **Accept** (string) - Required - application/json - **X-Postmark-Account-Token** (string) - Required - Account token for authentication. #### Request Body - **Name** (string) - Required - The name of the server. - **Color** (string) - Optional - The color of the server in the server list for quick identification. Possible options: `Purple`, `Blue`, `Turquoise`, `Green`, `Red`, `Yellow`, `Grey`, `Orange`. ### Request Example ```json { "Name": "Production", "Color": "Purple" } ``` ``` -------------------------------- ### Import Postmark .NET Library Source: https://postmarkapp.com/developer/integration/official-libraries Import the necessary PostmarkDotNet namespace to use the library. ```csharp using PostmarkDotNet; ``` -------------------------------- ### Import Postmark PHP Library Source: https://postmarkapp.com/developer/integration/official-libraries Include the Composer autoloader and use the PostmarkClient class. ```php require_once('./vendor/autoload.php'); use Postmark\PostmarkClient; ``` -------------------------------- ### Postmark Python SDK Client Initialization Source: https://postmarkapp.com/developer/integration/official-libraries Initialize Postmark Server or Account clients using async context managers for automatic connection closing, or by calling close() explicitly. ```python import postmark # Use as async context managers to ensure connections are closed async with postmark.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"]) as client: ... async with postmark.AccountClient(os.environ["POSTMARK_ACCOUNT_TOKEN"]) as account: ... # Or call close() explicitly when done client = postmark.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"]) await client.close() ``` -------------------------------- ### Send Templated Email on User Signup Source: https://postmarkapp.com/developer/integration/ai-prompts This snippet demonstrates sending a templated welcome email to a new user upon signup. It uses the Postmark client to send an email with a specific template and model, including user details and product URLs. Ensure the 'welcome@yourdomain.com' address is configured and the 'welcome' template exists in your Postmark account. ```javascript eventBus.on(UserEvent.SIGNUP, async ({ user }) => { try { await client.sendEmailWithTemplate({ From: 'welcome@yourdomain.com', To: user.email, TemplateAlias: 'welcome', TemplateModel: { user_name: user.name, product_url: process.env.APP_URL, action_url: `${process.env.APP_URL}/getting-started` }, MessageStream: 'outbound' }); } catch (error) { console.error('Failed to send templated email:', error); } }); ``` -------------------------------- ### Create a Server Source: https://postmarkapp.com/developer/api/servers-api Create a new server for your account. This request requires account-level privileges and an account token. You can specify the server's name and color. ```curl curl "https://api.postmarkapp.com/servers" \ -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "X-Postmark-Account-Token: account token" \ -d '{ "Name": "Production", "Color": "Purple" }' ``` -------------------------------- ### Get bounce counts Source: https://postmarkapp.com/developer/api/stats-api Gets total counts of emails you’ve sent out that have been returned as bounced. ```APIDOC ## GET /stats/outbound/bounces ### Description Gets total counts of emails you’ve sent out that have been returned as bounced. ### Method GET ### Endpoint /stats/outbound/bounces ### Parameters #### Query Parameters - **tag** (string) - Optional - Filter by tag - **fromdate** (string) - Optional - Filter stats starting from the date specified (inclusive). e.g. 2014-01-01 - **todate** (string) - Optional - Filter stats up to the date specified (inclusive). e.g. 2014-02-01 ### Request Example ``` curl "https://api.postmarkapp.com/stats/outbound/bounces?fromdate=2014-01-01&todate=2014-02-01" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` ``` -------------------------------- ### Example Response for Retrying Inbound Message Source: https://postmarkapp.com/developer/api/messages-api This is an example of a successful response when retrying a failed inbound message. ```http HTTP/1.1 200 OK Content-Type: application/json { ErrorCode: 0 Message: "Successfully rescheduled failed message: 041e3d29-737d-491e-9a13-a94d3rjkjka13." } ``` -------------------------------- ### Overview of Server Sandbox Mode Source: https://postmarkapp.com/developer/user-guide/sandbox-mode/server-sandbox-mode This section provides a general overview of Postmark's Server Sandbox Mode. It's useful for understanding the purpose and basic functionality of the sandbox. ```text Server sandbox mode Overview Endpoint URL Authentication HTTP response codes API error codes ``` -------------------------------- ### Get a message stream Source: https://postmarkapp.com/developer/api/message-streams-api Retrieves the details of a specific message stream by its ID. Use this to get information about a single stream. ```APIDOC ## GET /message-streams/{messageStreamId} ### Description Retrieves the details of a specific message stream. ### Method GET ### Endpoint /message-streams/{messageStreamId} ### Parameters #### Path Parameters - **messageStreamId** (string) - Required - The ID of the message stream to retrieve. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the message stream. - **name** (string) - The name of the message stream. - **message_stream_type** (string) - The type of the message stream (e.g., "Transactional", "Broadcast"). - **created_at** (string) - The timestamp when the message stream was created. - **updated_at** (string) - The timestamp when the message stream was last updated. - **archived_at** (string) - The timestamp when the message stream was archived, or null if not archived. ### Response Example { "id": "271828", "name": "Transactional", "message_stream_type": "Transactional", "created_at": "2023-01-01T10:00:00Z", "updated_at": "2023-01-01T10:00:00Z", "archived_at": null } ``` -------------------------------- ### Create a Welcome Email Mailable Class Source: https://postmarkapp.com/developer/integration/ai-prompts Define a Mailable class for welcome emails. This example demonstrates how to set the subject, tags, metadata, and specify a Markdown template for the email content. ```php // app/Mail/WelcomeEmail.php $this->user->id, ], ); } public function content(): Content { return new Content( markdown: 'emails.welcome', ); } } ``` -------------------------------- ### Clone Postmark Python SDK Repository Source: https://postmarkapp.com/developer/integration/official-libraries Clone the postmark-python repository and install dependencies using poetry. Set up pre-commit hooks for development. ```bash git clone https://github.com/ActiveCampaign/postmark-python.git cd postmark-python poetry install poetry run pre-commit install ``` -------------------------------- ### Get browser usage Source: https://postmarkapp.com/developer/api/stats-api Gets an overview of the browsers used to open links in your emails. This is only recorded when Link Tracking is enabled for that email. ```APIDOC ## GET /stats/outbound/clicks/browserfamilies ### Description Gets an overview of the browsers used to open links in your emails. This is only recorded when Link Tracking is enabled for that email. ### Method GET ### Endpoint /stats/outbound/clicks/browserfamilies ### Parameters #### Query Parameters - **fromdate** (string) - Required - Filter stats starting from the date specified (inclusive). e.g. 2014-01-01 - **todate** (string) - Required - Filter stats up to the date specified (inclusive). e.g. 2014-02-01 - **messagestream** (string) - Optional - Filter by message stream. If not provided, the response will include stats for all streams in the server. ### Request Example ```curl curl "https://api.postmarkapp.com/stats/outbound/clicks/browserfamilies?fromdate=2014-01-01&todate=2014-02-01" \ -X GET \ -H "Accept: application/json" \ -H "X-Postmark-Server-Token: server token" ``` ### Response #### Success Response (200) - **Days** (array) - List of objects that each represent browser usage by date. - **Date** (string) - The date of the statistics. - **Client (e.g. Safari mobile)** (integer) - Indicates total number of of times the given browser was used to open a tracked link in your emails. #### Response Example ```json { "Days": [ { "Date": "2014-01-01", "Google Chrome": 1, "Safari mobile": 1 }, { "Date": "2014-01-02", "Google Chrome": 1, "Safari mobile": 2 } ], "Google Chrome": 6, "Safari mobile": 8 } ``` ```