Skip to content

pavitrabhalla/GoMail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GoMail

A reliable RESTful email service backend to send emails

Why do you want this

Email is the most common way businesses interact with their customers to keep them engaged, interested and informed. Today, businesses are highly relied upon email service providers for doing the job right, but still there are events of failure that can lead to a huge loss in customer retention, money and efforts.

What does this do

GoMail uses a failover architecture to guarantee that emails are sent and never dropped. It provides an abstraction between two different service providers, making sure that if one fails, the service can failover to the other. This decreases the chances of failure in sending emails significantly.

Take a test drive

This project is hosted on an AWS EC2 instance, so you can easily try it out.
Fill in the variables below and execute the curl from your terminal -
senderaddress - Replace with an email address you want to use as the "from" address
recipientaddress - Replace with an email address you want to send the email to
pathtofile - To test sending an attachment, provide the full path to a local file
curl -X POST \
      -H "Content-Type: multipart/form-data" \
      -F "from_address=<senderaddress>" \
      -F "to_addresses=<recipientaddress>" \
      -F "subject=Testing my email service" \
      -F "body=Hi, this is a sample email from my email service" \
      -F "my_attachment=@<pathtofile>" \
    "http://ec2-54-67-40-84.us-west-1.compute.amazonaws.com:8080/api/v1/email-service/send-email/"
      
API
/api/v1/email-service/send-mail/
Request Parameters:
1. Content-Type: Use "application/json", if sending a JSON body without attachments. To send attachments, use "multipart/form-data" 2. from_address(String): A single email address as string. This will be the "from" address displayed in the email. If this is not passed, a default address will be used to send the email. 3. to_addresses(String): Multiple recipient email addresses delimited by a space. This is a required field. 4. subject(String): Subject for the email. Defaults to empty. 5. body(String): Accepts plain/text or HTML formatted string. This will be the body of the email. 6. Attachments: For sending attachments, use the name of the file as the key and the path to the file as its value. You can send multiple attachments along with the email. Maximum size allowed for all attachments together is 7MB.
Response
Returns an HTTP response with appropriate HTTP response codes - 
Success codes: 200 HTTP CREATED
Failure codes: 400 BAD REQUEST (The request is malformed, or the server could not decode the body of the request)
               403 FORBIDDEN (The server understands the request, but cannot do any further processing)
               500 INTERNAL SERVER ERROR (An unexpected error occured internally)
               501 NOT IMPLEMENTED (Malformed url)
               405 METHOD NOT ALLOWED (Invalid HTTP method)
Response body (JSON):
      {"success": <True/False for success and failure respectively>
      "message": <Response message from server>}

How does it work

GoMail uses Amazon Web Services-Simple Email Service (AWS SES) and SendGrid as the two email service providers. These services are highly reliable, provide extensive developer support and are easy to integrate with Python. GoMail chooses AWS SES as the default service to send email, but if it fails or SES goes down, it switches to Sendgrid to fulfill the request.

Under the hood

The service is built using Python and Django. This is mainly because I have been working with this stack at my current job for about a year now. Tastypie is used as the webservice API framework with django. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces.

Potential future additions to GoMail

Functional
1. Handling CC and BCC recipients 2. Adding authentication, authorization for API usage 3. API to add a default signature for a "to" address 4. API to get mail delivery status 5. Adding recipient group for a "from" address to send mass emails frequently 6. Upload a csv for list of recipients
Internal, Design and Architecture
1. Add verbose logging 2. Preliminary checks on uploaded files for size and malware content. 3. Add users model, that implements authentication, control and access rights 4. Storing events in database, along with the status of delivery 5. Adding detailed error codes and publishing it to the API documentation

Build your project

1. Download the source code from github, and go into the root directory of the project 2. On unix systems, run - pip install -r requirements/requirements.txt. This will install all the required packages for the project. 3. Signup for Sendgrid and AWS SES. Also, verify your email address with AWS. You can use this email address as the DEFAULT_FROM_EMAIL in your settings.py, as shown below. 4. Modify the following variables in settings.py with your credentials -
    #Default Email Settings
DEFAULT_FROM_EMAIL = '<default_from_email>'
DEFAULT_TO_EMAILS = '<default to email addresses delimited by a single blankspace>'
    #Sendgrid Credentials
SG_USERNAME = '<sendgrid_username>'
SG_PASSWORD = '<sendgrid_password>'
    #AWS Credentials
AWS_ACCESS_KEY_ID = '<AWS_ACCESS_KEY_ID>'
AWS_SECRET_ACCESS_KEY = '<AWS_SECRET_KEY>'
AWS_SES_REGION = '<AWS_SES_REGION>'
    #API Base URL
API_BASE_URL = <Base url to where your application is hosted>

Run the test suite

Once you have setup your accounts, and changed the settings, run the test suite and check your inbox at the default "to" addresses. This is how you can run the tests -
 ./manage.py test api 

Me

You can find my Resume here - http://bit.ly/1ET4En3

About

A reliable RESTful email service backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages