Automating Post-by-Email

One nice feature to have in a blog is post-by-email. It’s mostly overlooked, and even not activated by default. What I like most is that I can write in my usual app, then use email to ship it off.

There are several dedicated blog postings apps available. Desk.pm and MarsEdit are the first that come to mind. I’ve not tried either, and that might change in the future. For now, I’m writing everything in Ulysses and it’s easier to keep it all together in one place. Plus, it keeps my browser closed, reducing distractions.

When posting to WordPress via email, there are ways to tag your message with shortcodes to control the posting process. What I’ve built is a way to add the email shortcodes automatically to the email body.

Benefits

  • Once set up, it works really fast. I can finish a post and turn it into an email in seconds.
  • No distractions. I only need my writing program and email. If incoming email is getting bothersome, I can go into offline mode and still create outgoing messages.
  • Works offline. I can send when I go back online.
  • Posts are backed up to your email sent folder.

Read on to find out how…

Getting set-up

Tools needed: Automator, text editor, and a finished post

Make sure the blog is set to receive email posts, the help page shows how. Make sure to save the secret email address to your address book.

The first step is to write a post. I use markdown and export to HTML, which then goes to WordPress. In Ulysses it’s simple as ⌘-6, choosing HTML and clicking Copy to Clipboard.

Ulysses' HTML export menu.
Ulysses' HTML export menu.

This is going to be pasted into an email message, but first I need to add the shortcodes.

The shortcodes are well documented on the help page. There are more options than the ones I’m using. Read that page if you’d like to include a poll or to schedule a post.

The codes I’m going to add are: title, status, tags, publicize, and end.

Title — This will be the post title. Usually it’s taken from the email subject line. Or it can be specified directly. I prefer using the tag. This way, I don’t have to worry about the email subject getting scrambled.

Status — There are four choices for setting post status: publish, draft, pending, and private. I use draft as my default. I like to review before the final publish.

Tags — Every post gets a tag or three. I don’t specify a category, so posts automatically get put in the default category.

Publicize — Sharing settings and a post excerpt. I’ll be using Twitter and Tumblr in this example. I can add hashtags and control exactly what shows up on Twitter.

End — I want to explicitly end the post, as not to pick up any email signatures or cruft.

Building a system service

First I’ll need a shell script. I keep mine in ~/bin for easy access. Using the terminal, create a text file named format-post and make it executable with the chmod +x. The following commands will do this:

cd ~/bin
touch format-post
chmod +x format-post

Now, open that file with a text editor, like vim or TextWrangler, and paste in the following code and save the file.


echo "[title TITLE]"
echo "[status draft]"
echo "[tags tag1,tag2]"
echo "[publicize twitter Tumblr]Title and hashtags[/publicize]"
echo ""
pbpaste
echo "[end]"

This prints out the shortcodes wrapped around whatever is on the clipboard. And it’s what I’ll use as the base of the system service.

To create a system service, open Automator and create a new project. Choose Service as it’s type. Add one element, Run Shell Script and set the options up like the picture below. The command to use is ~/bin/format-post | pbcopy.

This is how the finished service should look.
This is how the finished service should look.

Save this as Format email post and verify that it appears in the service menu.

Look, A new menu item!
Look, A new menu item!

Workflow

Once this is set up, posting by email is easy. These are my steps.

  1. Write a post in Ulysses.
  2. Use ⌘-6, click the HTML icon, then click Copy to Clipboard.
  3. Open a new mail message.
  4. Activate Format email post from the service menu.
  5. Paste the clipboard into the blank email body.
  6. Adjust my shortcodes as needed.
  7. Send mail.
  8. Review the draft post.
  9. Publish when ready.

I hope this works as well you as it does for me.

Hint: WordPress will also accept emails containing images, and saves them to the media library. Then it will send back a confirmation email. This email will have the links needed to add the URLs into a post. I think it’s a bit faster than doing the web-based upload. See the help page for more information.