🐙 Check out Postmark's new MCP Server!
x
How to send test messages via SMTP | Postmark Support Center

How to send test messages via SMTP

Sometimes you may need to send a test message through SMTP to confirm that your configuration works correctly or to replicate a specific issue. While simple tools like SMTPer can help you test basic sending, creating your own test setup gives you much more control over the message — including headers, attachments, content, and authentication details.

This guide walks you through setting up a local test environment and sending a message through Postmark using PHPMailer.


1. Install the necessary tools

You’ll need three main tools:

  • Homebrew — a package manager for macOS.

  • PHP — for running your test script.

  • A code editor — such as Brackets, Visual Studio Code, or Sublime Text.

Install Homebrew

Visit https://brew.sh/ and copy the installation command from the site.

Then:

  1. Open Terminal on your Mac (press Command + Space, type “Terminal,” and hit Enter).

  2. Paste the command and press Enter.

  3. Enter your Mac password when prompted.

  4. Wait until you see Installation successful!.

Install PHP

Once Homebrew is installed, run this command in Terminal:

 
brew install php

This installs the latest version of PHP. You can confirm it’s installed by running:

 
php -v

You should see something like PHP 8.1.x.


2. Download and set up PHPMailer

PHPMailer is a popular library for sending email through PHP and makes it easy to work with SMTP.

  1. Download PHPMailer from GitHub (click the green Code button → Download ZIP).

  2. Extract the ZIP file to your Desktop or another folder.

  3. Open the folder in your code editor.

  4. Locate the example file — typically named php_mailer_example.php.

This file contains properties like Username, Password, Subject, SetFrom, etc. Each line is commented for guidance. You’ll just need to edit the values inside the quotes.


3. Update the email details

Here’s what to update in the file:

Authentication

Add your Postmark Server API token for both the username and password fields:

 
$mail->Username = "YOUR_POSTMARK_SERVER_TOKEN"; $mail->Password = "YOUR_POSTMARK_SERVER_TOKEN";

Message stream (optional)

By default, messages will send through your Transactional message stream.
If you want to send through a Broadcast or another stream, add or edit this header:

 
$mail->addCustomHeader('X-PM-Message-Stream: broadcast');

Replace broadcast with your actual message stream ID.

Sender and recipient

Use verified sender addresses from your Postmark account:

 
$mail->SetFrom('sender@example.com', 'Your Name'); $mail->AddAddress('recipient@example.com', 'Recipient Name');

If you’re not including CC or BCC, remove those lines entirely — leaving them blank will cause an error.

Email body and subject

 
$mail->Subject = "SMTP Postmark Test"; $mail->Body = "This is a test email sent via Postmark SMTP using PHPMailer.";

Attachments (optional)

You can safely leave this line in your file (even if you don’t include an attachment):

 
$mail->addAttachment('example.pdf');

If you do want to include an attachment, make sure the file exists in the same folder as your PHP script.

✅ Save your file when done.


4. Send a test message

Now you’re ready to send your test message!

  1. Open Terminal again.

  2. Navigate to your PHPMailer folder (for example, if it’s on your Desktop):

 
cd Desktop cd PHPMailer-master
  1. Run your test script:

 
php php_mailer_example.php

If everything is configured correctly, you’ll see output similar to this:

250 OK queued as 12345abcdef

 

That unique “queued as” ID is the Postmark Message ID — you can share it with Postmark Support if you’d like us to confirm delivery in our logs.


5. How to include an attachment

To attach a file, add this line anywhere before sending:

 
$mail->addAttachment('returnlabel.pdf', 'Return label');
  • The first parameter is the file path.

  • The second (optional) parameter is the filename as it will appear to the recipient.

For example, if your file is located in the same folder as your script:

 
$mail->addAttachment('returnlabel.pdf');

6. Troubleshooting

Issue Possible Cause Fix
Could not authenticate Incorrect Postmark token or wrong SMTP credentials Verify you’re using your Server API Token for both username and password
No message appears in Postmark Not sending from a verified sender or wrong stream header Check your From address and ensure the correct stream
“Empty address” or syntax error Missing or blank field Remove unused fields like CC/BCC
“Connection refused” SMTP blocked by firewall Try from a different network or confirm port 587 is open

Summary

You’ve now created a full test setup for sending emails via SMTP.
This approach gives you full control over message details — including headers, attachments, and streams — making it a powerful way to troubleshoot delivery or replication issues.

If you run into any problems or want help reviewing your test results, you can contact Postmark Support and share your message ID or test output.

Last updated October 27th, 2025

Still need some help?

Our customer success team has your back!