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/"
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>}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. 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. 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 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 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>
./manage.py test api