Charlie Harvey

Using from Bash

I recently learned of a new web publishing tool called, which lets you publish stories to a custom url by sending email to a particular email address. Quite a nifty idea.

The service is a model of minimalist, yet highly functional design. The simplest thing that could possibly work, you might say. As well as publishing your html emails, it lets you send it images or markdown as attachments and does something sane with those.

But I spend most of the time in a terminal somewhere or other, so it seemed to me that the obvious next step was to be able to edit my file in vim, and send the email straight to the web. With a temporary throwaway email address. Perhaps through tor if I cared about anonymity, though I imagine there would be some traitorous headers that may threaten my anonymity. Here’s a little script that I developed so that I could publish an html file from my local environment straight to without ever leaving the shell.


To make this work I will need a temporary email provider. I chose to use I am normally a fan of mailinator, but it doesn’t work through lynx (if you’re listening, mailinator folks …). I also need a server with a sendmail command, and root access so that I can spoof my sender address and make html email. And, of course, an html file which I want to publish walk through

First of all I set up a few variables that will be useful later on and signify this is a bash script. #!/bin/bash SENDMAIL="/usr/sbin/sendmail" USAGE="Usage: `basename $0` html_file_to_upload" MAILPIN_IN='' SHOW_IN_LYNX=1 The path to sendmail may vary on your system. SHOW_IN_LYNX can be set to 1 to pop up lynx in our temporary email account. If it is set to anything else the script just dumps the URL to the screen, for cut and pasting.

Now I check for a couple of common errors: running the script as a non-root user, and not providing an html file to send to if [ $(id -u) -ne 0 ] then echo You must be root 1>&2 echo $USAGE exit 1 fi if [ $# -ne 1 ] then echo Missing html filename 1>&2 echo $USAGE exit 65 fi Note that I pipe the error messages to STDERR with the 1>&2 construction. And even do proper exit codes. This may be a trivial script, but no doubt I will end up doing something important with it one day. I might as well doo things properly.

I use an md5sum of the file to generate a random string which I'll use as my mailbox name. randstr=`md5sum $1 | cut -d' ' -f 1`

Finally, with the infrastructure in place, it is time to actually send the email, print the mailbox URL and open our browser. The code is only three lines (echo 'Subject: Commandline post';echo 'Content-type: text/html; charset="utf8"';echo;cat $1) | $SENDMAIL -f$ $MAILPIN_IN echo Confirmation mail should be found at at$randstr if [ $SHOW_IN_LYNX -eq 1 ] then sleep 5 lynx -accept_all_cookies$randstr fi The first line prints the subject header, then a header to make the email HTMLish, then a blank line, so that we know the headers are over, then cats our html input file. This lot is then piped through to sendmail which we call with -f to spoof our email address. Next we print our mailbox url. Finally, we check whether to call lynx and if we should, we pause five seconds then open lynx. Which gives a while to catch up.

Now I can call my thus (actual URL edited, should be longer) $ sudo ./ x.html [sudo] password for myuser: Confirmation mail should be found at at

Wrapping up

You can grab the complete script if you want to have a play.

With relatively little effort I was able to implement a toy posting tool for my personal amusement. The service is very cool and I believe that it will become popular because of its simplicity and convenience. In the real world, this is a much less convenient way to push html files to the internets than, say, sftp. But I enjoyed excercising my bash muscles a little to make something slightly impractical but somewhat usable.


  • Be respectful. You may want to read the comment guidelines before posting.
  • You can use Markdown syntax to format your comments. You can only use level 5 and 6 headings.
  • You can add class="your language" to code blocks to help highlight.js highlight them correctly.

Privacy note: This form will forward your IP address, user agent and referrer to the Akismet, StopForumSpam and Botscout spam filtering services. I don’t log these details. Those services will. I do log everything you type into the form. Full privacy statement.