This app uploads emails it receives to S3. Out of the box, it works well to create "View On Web" links within personalized emails.
- Parse Webhook - This app relies on the SendGrid Parse Webhook, however, it could be configured to use another webhook.
- AWS Account
- Hosting Provider - Heroku is ready to go, however, you can upload to any provider that supports webhooks.
To start using this app you must do two things: deploy the app and setup your parse webhook.
- Clone the repository to your computer.
git clone https://github.com/nquinlan/save-mail.git save-mail
- Move into the repository.
cd save-mail
- Initialize Heroku.
heroku init
- Provide Heroku with your app's credentials.
heroku config:set S3_ACCESS_KEY_ID=your-s3-access-key S3_SECRET_ACCESS_KEY=your-s3-secret-key S3_BUCKET=your-s3-bucket
- Deploy to Heroku.
git push heroku master
- Setup a webhook to post to your new Heroku app.
This will start saving all mail received by the domain the Parse Webhook is setup on.
By default Save Mail saves each email with a Universally Unique Identifier, however, you may specify what you wish the file name to be instead.
You may specify the URL (or at least the file name) you intend for the stored email to have by specifying an X-Save-Mail-ID
in the headers of your message (as seen below). This ID will be the file name for the email when uploaded to S3.
X-Save-Mail-ID: super-cool-message
The message will be stored on S3 at http://s3.amazonaws.com/your-bucket-name/super-cool-message.html
All files stored by Save Mail have the extension .html
Save Mail comes with two templates, found in _templates, however you may modify and change these how you wish. To have an email be stored with a certain template, simply send your email with an X-Save-Mail-Template
header (as seen below). This will save the message with the specified template
X-Save-Mail-Template: preserve-headers
The message will be saved with the template preserve-headers.html.erb
.
Although this code is meant for the SendGrid Parse Webhook, it should also work with a few other services, with limited changes: (Warning: These have not been tested)
- Mandrill should work without modification
- zapier might work, but they sure do hide their documentation. Make sure
html
andheaders
parameters are POSTed as a form. - cloudmailin change
params[:headers]
toparams[:message]
and use their original HTTP POST format. - mailgun change
Mail.new(params[:headers])
to simplyparams[:message-headers]
This code is licensed MIT. Please, build things with it.