Set up DMARC and see who's sending email using your brand's domain.
x

Feature announcement: introducing the Postmark CLI

Today, we’re super excited to announce that Postmark now has an official command-line interface 🎉. We built a proof of concept earlier this year during our company-wide hack week, and now it’s available for everyone!

Postmark CLI

Version 1.0.0 supports pushing and pulling templates, sending emails, and fetching server lists, all from the command-line. This makes Postmark and your CI/CD pipeline go together like peas and carrots.

Installation #

Before you get started, install Node.js and make sure that your Postmark server and account tokens are handy.

From the command line, run:

npm i postmark-cli -g

Once npm does its thing, run the postmark command and you will see some high-level usage details. You’re all set!

Protip: You’ll be asked to authenticate by entering your server or account token each time you run a command. If you prefer, you can bypass this step by supplying tokens as environment variables.

Push and pull email templates #

Have you gone to bed at night dreaming of a time where you could store email templates in git and automate the deployment process? Dream no more! 

Start by downloading your templates from Postmark using the templates pull command, followed by the path of where you want to save your templates:

postmark templates pull ~/my-emails

The directory structure will look a little something like this:

my-emails
├── _layouts
│   └── plain
│       ├── content.html
│       ├── content.txt
│       └── meta.json
└── password-reset
│   ├── content.html
│   ├── content.txt
│   └── meta.json
└── welcome
    ├── content.html
    └── meta.json

Layouts are located under the _layout folder and standard templates will be located in the root. Each template or layout gets its own folder that contains the HTML and text content, along with metadata in a JSON file. From here, you’re free to code up some HTML like it’s 1995... or go ahead and commit to your git repository. Up to you.

When you’re ready to push your templates to Postmark, use the templates push command, followed by the template path:

postmark templates push ~/my-emails

Before the templates get pushed, you’ll see a summary of changes. You can see whether a template will be modified or newly added to the server. If you’ve pushed templates in the UI, this might look a little familiar. Confirm your changes by typing y and hitting enter.

Confirming template pushes using the Postmark CLI

There you have it! Your templates are now up on Postmark. If automation is your thing, you can even use a CI/CD tool like Travis CI or CircleCI to trigger pushes from git commits. More details about the templates command are up on our wiki.

Send emails #

Our CLI tool also supports email sending. You might find this useful for triggering email notifications as part of a build process. I, however, use it for emailing my grandma:

postmark email raw --from="derek@wildbit.com" --to="grandma@grandma.com" --subject="Hi Grandma" --html="<marquee>Want to grab ice cream later?🍦</marquee>"

The email raw command works similarly to our public email API endpoint, where the HTML and text content gets passed along with every request. We even support templated emails as well. Check out the wiki for more details.

Fetch server lists #

Now you can quickly see a list of Postmark servers on your account, jump to the server dashboard from your web browser, or grab tokens for development.

Run postmark servers list and authenticate with your account token:

Listing servers using the Postmark CLI

Server tokens are masked by default just to be safe. You can show the tokens by passing in the --show-tokens flag. Tread with caution though, this means your server tokens will appear in your command-line history. Be sure to check out the wiki for more nifty tricks.

That’s a wrap! #

We hope you are as excited as we are about this. You’ll find all the details you need to get up and running on our Github repository. As always, we’d love to hear your feedback.

🛸TOP SECRET TIP: Run postmark cheats if you’re feeling up to it.

Derek Rushforth

Derek Rushforth

Designer, developer, doodler. Likes tacos and badminton.