A Python library to send emails by accepting JSON data through HTTP POST requests.
Linux
$ sudo apt-get install git-core
Windows
Click here for instructions on installing Git for Windows
Linux
$ sudo apt-get install python-setuptools
$ sudo easy_install virtualenv
Windows
Click here for instructions on installing virtualenv and pip for Windows
Replace {PROJECT_HOME}
with your desired directory path and name: for instance /email_service or /home/{username}/email_service)
$ mkdir /{PROJECT_HOME}
$ cd /{PROJECT_HOME}
Linux
$ git clone https://github.com/darshanrp/email_service.git
Windows (use Git Bash)
$ cd /{PROJECT_HOME}
$ git clone https://github.com/darshanrp/email_service.git
Linux and Windows (use Powershell or Command Prompt)
$ cd /{PROJECT_HOME}/email_service
$ virtualenv ENV
Linux
$ source ENV/bin/activate
Windows
$ cd ENV/Scripts
$ activate
$ cd /{PROJECT_HOME}/email_service
Linux and Windows (use Powershell or Command Prompt)
(ENV)$ pip install -r requirements.txt
- Replace
{MAILGUN_DOMAIN}
with the appropriate mailgun domain for Mailgun account - Update
API_KEY
with Mailgun api key for your account - Update
ALT_API_KEY
with Mandrill api key for your account - Update
SERVER_PORT
with appropriate port number - Update
TIMEZONE
(Eg. 'US/Pacific' or 'US/Eastern')
Linux and Windows (use Powershell or Command Prompt)
(ENV)$ python email_service.py
In order to make a HTTP POST request to the webservice you can use the following curl command
$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"to":"darshan@gwu.edu","to_name":"Darshan Pandhi","from":"noreply@uber.com","from_name":"Uber","subject":"Test message from Uber","body":"Your bill is $10."}' http://localhost:8081/email
-
Delayed email delivery
For delayed email delivery add the param
send_at
$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"to":"darshan@gwu.edu","to_name":"Darshan Pandhi","from":"noreply@uber.com","from_name":"Uber","subject":"Test message from Uber","body":"Your bill is $10.","send_at":"2014-06-30 10:45:00"}' http://localhost:8081/email
Note: To use curl on Windows, use curl command in git bash or follow installation instructions here
I started reading about Flask framework and I found it nimble and a perfect fit for such small applications. It has a handful of useful modules for building a standalone app. Flask is small yet powerful framwork based on Werkzeug and Jinja2. Flask immediately caught my interest and I wanted to learn and use it. Hence I chose Python and Flask for this task.