Giter VIP home page Giter VIP logo

gomail's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.