Sending email is great, but sometimes you want a little more. Maybe you want to store every email you send your users. Or maybe you want to allow your users to share your emails on their social networks. Maybe, you simply want to allow users to see the email online, in case their email reader breaks it.
Well, I made a simple app to do that, with Amazon S3.
The app (
available on Github) is relatively small and easy to implement. Follow the
Quick Start Guide to get an instance of the app up and running. This will get you a Heroku instance running the app and the
SendGrid Parse Webhook configured. Now you have an application that will store any email it
recieves, however, it's not yet storing all email you send.
To have the app store every email you send, you'll simply need to enable the
BCC app, found in your
app dashboard. Set the app to BCC all mail to an address on the Parse Webhook domain you setup earlier. Now, all email you
send will be stored on S3.
You may, however, want to link to the stored email,
when you send it. Luckily with this app, you may. To do so, include an
X-Save-Mail-ID header in the email you're sending. This header, tells the app what to name the saved file (so you can link to it, before it's been created). You can make the filename anything as long as you ensure it will be unique. Most languages have a
Universally Unique Identifier (UUID) function that will allow you to do this, although you can also simply hash the email contents with the microtime and be fairly safe. If your UUID or approximation is "ABC", you may then link to the file in the email with the URL:
http://s3.amazonaws.com/your-bucket-name/ABC.html. An example makes this a little more clear (it's in PHP but you can do this in any language):