This project uses Amazon Lambda and API Gateway to forward emails using Amazon SES. It can be used on a static web site for example hosted on S3 as a contact form.
It is written in python and uses Chalice.
To deploy it:
- Create a virtualenv with
virtualenv venv
then install the requirements withpip install -r requirements.txt
. - Export your AWS credentials in your shell
- Rename
email-forwarder
to something else - Run
chalice new-project email-forwarder
- Move the contents of whatever you renamed
email-forwarder
to into theemail-forwarder
directory generated by chalice. - Change into the
email-forwarder
directory. - Edit
chalicelib/config.ini
, updating it as necessary. - Run
chalice deploy
from the directory containingapp.py
.
Note: If you're committing this to git, make sure to remove .chalice
from email-forwarder/.gitignore
to commit your chalice config files.
You can now POST JSON encoded messages with the following structure to the endpoint returned by chalice:
{
"sender_name": <optional field for the sender's name>,
"sender_email": <optional field for the sender's email address>,
"body": <required field - the email body>,
"domain": <required field - the domain of the site hosting the form.
This will be put in the subject field>,
}
Note: You need to set the content type to 'application/json'.
To use this, deploy as above, then generate a javascript SDK by running
chalice generate-sdk examples/sdk
and create a form like:
<form>
<!-- Change this to match a whitelisted domain in `config.ini` -->
<input type="hidden" name="domain" value="example.com" />
<p><input type="text" name="sender_name" /></p>
<p><input type="email" name="sender_email" /></p>
<p><textarea name="body></textarea></p>
<p><input type="submit"></p>
</form>
Finally, create some javascript to submit the form. You need to use javascript
to submit the form because it needs to be submitted as JSON with a content type
of application/json
which isn't possible when directly submitting the form
in a browser.
For a complete example, see the examples
directory.