Send Email Newsletters via Command Line With Postman
If you're wanting to start a new email newsletter—or find a better way to send out your existing newsletter—there's quite a few tools for you. There's MailChimp and many other online email services, as well as tools built into Office apps like Word and Outlook's Mail Merge and a similar feature with new Google Docs add-ons. But if you're used to coding your own sites and using the terminal, there's a better option: the terminal app Postman.
In this tutorial, I'll show you how to effectively use Postman to send your email newsletters via any SMTP server: your own server or email account, or services like Amazon SES or Mandrill. We’ll cover creating a basic recipient list, creating a basic email template, different mail sending options, and finally what a full example looks like. With those building block examples under your belt, you'll be able to send any email newsletter the way you want.
Getting Started With Postman
This tutorial is going to assume you are comfortable installing support for the go programming language in your operating system environment and setting a couple path related environment variables.
I will briefly demonstrate how to get this up and running on your Mac, but please reference the documentation I linked to above before moving on—and note that you can get it running using similar steps on any Linux computer, and with a bit more effort on a Windows PC.
Installation on OS X
One prerequisite for installation on OS X is homebrew. Please read the documentation and setup homebrew before moving forward.
Now that you have homebrew all setup and up to date, run the brew command to install go. I’ll show all the output you should see below.
1 |
[chadhs@mac ~]$ brew install go |
2 |
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/go-1.2.2.mavericks.bottle.tar.gz |
3 |
######################################################################## 100.0% |
4 |
==> Pouring go-1.2.2.mavericks.bottle.tar.gz |
5 |
==> Caveats |
6 |
As of go 1.2, a valid GOPATH is required to use the `go get` command: |
7 |
http://golang.org/doc/code.html#GOPATH |
8 |
|
9 |
`go vet` and `go doc` are now part of the go.tools sub repo: |
10 |
http://golang.org/doc/go1.2#go_tools_godoc |
11 |
|
12 |
To get `go vet` and `go doc` run: |
13 |
go get code.google.com/p/go.tools/cmd/godoc |
14 |
go get code.google.com/p/go.tools/cmd/vet |
15 |
|
16 |
You may wish to add the GOROOT-based install location to your PATH: |
17 |
export PATH=$PATH:/usr/local/opt/go/libexec/bin |
18 |
|
19 |
Bash completion has been installed to: |
20 |
/usr/local/etc/bash_completion.d |
21 |
|
22 |
zsh completion has been installed to: |
23 |
/usr/local/share/zsh/site-functions |
24 |
==> Summary |
25 |
🍺 /usr/local/Cellar/go/1.2.2: 3981 files, 115M |
Now that you have go support installed, lets setup our environment.
1 |
[chadhs@mac ~]$ mkdir $HOME/go |
2 |
[chadhs@mac ~]$ export GOPATH=$HOME/go |
3 |
[chadhs@mac ~]$ export PATH=$PATH:$GOPATH/bin |
To continue using postman or other utilities requiring go, we need to make these environment settings persistent. You’ll need to add them to your shell’s rc or profile file that gets loaded when launching a new terminal session. I’ve yet to join the ranks of the zsh folks full-time, so here’s what I put into my .bashrc after PATH is defined.
1 |
export GOPATH=$HOME/go |
2 |
export PATH=$PATH:$GOPATH/bin |
Now let’s install postman using go.
1 |
[chadhs@mac ~]$ go get github.com/zachlatta/postman |
Run the postman command after installation completes, to verify you’ve done everything correctly. You should see the following output.
1 |
[chadhs@mac ~]$ postman |
2 |
Postman is a utility for sending batch emails. |
3 |
|
4 |
Usage: |
5 |
|
6 |
postman [flags] |
7 |
|
8 |
Flags: |
9 |
|
10 |
-attach attach a list of comma separated files |
11 |
-c number of concurrent requests to have |
12 |
-csv path to csv of contact list |
13 |
-debug print emails to stdout instead of sending |
14 |
-html html template path |
15 |
-password smtp password |
16 |
-port port of smtp server |
17 |
-sender email to send from |
18 |
-server url of smtp server |
19 |
-subject subject of email |
20 |
-text text template path |
21 |
-user smtp username |
Creating a basic recipient list
The next thing you need is a list of contacts to send your email to. For our example you’ll need to create a blank text file named recipients.csv. In that text file you’ll enter “Email, Name, Type” on the first line, and then all of your contacts following that format, one per line. Be sure to save the file once you’re done checking that everything has been entered correctly.
1 |
Email,Name,Type |
2 |
chadhs@example.com,Chad Stovern,Human |
3 |
info@techcraft.example.com,Techcraft Workshop,Robot |
4 |
cstovern@work.example.com,Chad Wokerson,Human |
Creating basic html & text email templates
Now that you have your list of email recipients created, let’s make two email templates that will hold our message. One template will be an html version and the other will be a text version to make plain text geeks like me happy. Feel free to deviate from copying and pasting my exact examples below. Play around with the wording and where you include the special “{{.Name}}” and “{{.Type}} entries. Those entries are ”variables" that will fill in the name and type from your recipients.csv contact list.
Here is about what your html version should look like:
1 |
<h1>Hello, {{.Name}} the {{.Type}}!</h1> |
2 |
|
3 |
<h2>
|
4 |
We'd like to take this opportunity to congratulate you on being |
5 |
featured as one of our top 25 {{.Type}} customers! |
6 |
</h2>
|
7 |
|
8 |
<h3>
|
9 |
Click here to claim your <a href="http://rewards.example.com/freeoffer">FREE Reward</a> |
10 |
</h3>
|
11 |
|
12 |
<p>
|
13 |
<strong>
|
14 |
Sincerely,<br>
|
15 |
Fake Marketing Robot |
16 |
</strong>
|
17 |
</p>
|
Here is approximately what your plain text version should look like:
1 |
Hello, {{.Name}} the {{.Type}}! |
2 |
|
3 |
We'd like to take this opportunity to congratulate you on being |
4 |
featured as one of our top 25 {{.Type}} customers! |
5 |
|
6 |
Click here to claim your FREE Reward: http://rewards.example.com/freeoffer |
7 |
|
8 |
Sincerely, |
9 |
Fake Marketing Robot |
Sending options to consider
Now that you have all the required pieces assembled, there’s one more piece to consider before we start sending mail. For tutorial purposes, using your gmail or other personal account to send mail is just fine. When you put this into practice “in the real world” you’ll want to weigh some options.
At a minimum, be sure you’re sending mail from the account you want people to see when the recieve your message. I could think of far worse advice than having a special marketing@example.com or customerservice@example.com address to send such messages from. The other thing to consider is email limits imposed by your provider. There may be limits on how many different external email addresses you can send to in any one particular 24 hour period. If your list is 500 or less you’re likely to be fine using your current email service to send out a weekly email campaign. If you want to do much more than this using postman as a tool, I would seriously look into a service such as sendgrid, Amazon SES or Mandrill to send your emails. Just signup for an account with any of the respective services and use their server settings with postman.
Gathering a Few Technical Details
The last piece of the puzzle is gathering some information about the mail account you’re going to use to send your email. You’ll need to know the following items:
- email address
- server name (such as: smtp.example.com)
- server port (such as: 587)
- user name (usually your email address)
- password
You will need these values handy before moving on and sending email.
Putting it All Together
Now let’s take all our work and do a live test. Run the same example I have below, substituting in your own information in place of mine. Be sure to pick a solid sounding subject line that matches the content of your message, but doesn’t send off sirens in a users head to reach straight for the delete button. You’re looking for the magic words “Emailed recipient X of X…” to appear, confirming your success. If postman just hangs indefinitely or you see another error, be sure to check your email server settings (user, password, server, port) again for any errors and then run postman again.
1 |
[chadhs@mac postman]$ postman -html template.html -text template.txt -csv recipients.csv -sender "Chad Stovern <chadhs@example.com>" -subject "A FREE gift for being our customer!" -server smtp.example.com -port 587 -user chadhs@example.com -password "nice-try-not-my-password" |
2 |
Emailed recipient 3 of 3... |
If everything worked on the command-line, wait for the emails to come in. You’ll know you followed our example correctly if you get the same email content, but the name and type fields were filled in appropriately with the values from your recipient list.



And another example, using the same email customized for another recipient:



Conclusion
With those building block examples under your belt, the possibilities are limitless. You can now spend time building some great reusable templates that you own and control, outside of any hosted marketing service. I highly recommend you stroll on over to Tuts+ web design for some great ideas on how to start building out and beautifying those templates.
If you have any further questions on using postman or are stuck and at your whit’s end; let me know in the comments below. As always, thanks for reading!