s3ify gem - put the assets for a HTML email online

I often have to deal with setting up email sends, which usually involves getting a zip file from a designer containing a html file and some images. I usually unzip, convert all the image references to point to an S3 path, upload the whole folder to S3 using S3fox, and change the permissions to be publicly readable.

This is a bit repetitive and manual for my liking so I wrote a small ruby gem to make it a bit simpler. It uses Nokogiri to parse the HTML (so you will need a recent version of libxml) and the aws-s3 gem to upload everything to S3. I used the commander gem to create a command line interface to use it.

So first, get it installed

sudo gem install mattfawcett-s3ify

You will need to have your Amazon web services access information set in your path, if you don’t have this already, your best bet is to create a hidden file in your home directory called .amazon_keys with the contents

export AMAZON_ACCESS_KEY_ID='abcdefghijklmnop'
export AMAZON_SECRET_ACCESS_KEY='1234567891012345'

then add the following to your shell’s rc file (usually .bashrc)

if [[ -f "$HOME/.amazon_keys" ]]; then
    source "$HOME/.amazon_keys";
fi

Then to use it simply open up a shell and type

s3ify -b my_bucket -p my_folder_in_bucket ~/Desktop/my-email/ 

The -b flag is the bucket you wish to upload to, the -p flag is the path in the bucket that you want to upload to and finally you declare the path to the folder where your HTML email is on the file system. For each HTML file, the gem will create an additional file with the prefix of “_s3” which will have the image references pointing to S3.

The code is on Github

Posted by Matt Sat, 27 Jun 2009 12:35:00 GMT


Trackbacks

Use the following link to trackback from your own site:
http://matthewfawcett.co.uk/trackbacks?article_id=9