Introduction

In large and complex software architectures it is very important to have reusable components across the software. In a microservices setup it is important to have services split by their funtionality. The idea behind the construction of this api is to have a global mailing api for the whole backend. This api can be used as an independent one. The mailing api is built using the bulk emailing service called Mailgun and a templating language call EJS (Embedded Javascript).

Mailgun is a simple but powerful emailing service which is economical and has a great dashboard to monitor all the mailing operations. As we are looking to have a scalable emailing api, the most important part is the templating language. In EJS we can create dynamically populated templates efficiently.

Funtionality

The mailing api can handle the functionality:

  1. Send bulk emails with cc and bcc
  2. Fill dynamic content and use custom designed templates
  3. Can handle array of attachments in the email
  4. Contains swagger documentation for the request structure
  5. Contains a sample email design template with slots for logo, socials etc.

How to use

You can clone the git repository fromhere. In order to use the repository a mailgun account needs to be configured

  • Configure mailgun
  • Buy a domain if you dont have one
  • Then register a mailgun account
  • Setup the subdomain as defined by mailgun. The suggested one is mg.example.com (You can also use a sandbox sending domain for test purposes. You can skip these steps if you do not want to do the setup. But it is anyways required if you want to use the full functionality of the api in production).
  • In your Settings > API Keys you can access your mailgun api

Steps to run the api

// step 1 - install dependencies
 
> npm install 
// step 2 - create a logs directly in the root folder of the project
> mkdir logs 
// step 3 - add the following parameters in the config file /root/config/config.js. // The sample domain and mail are filled in the code already, but cannot be used.
domain: 'YOUR MAILGUN SUBDOMAIN GOES HERE', 
apiKey: 'YOUR MAILGUN API KEY GOES HERE', 
from: 'YOUR DEFAULT FROM EMAIL GOES HERE', 
// step 4 - run the api 
> npm run dev

Your api is running in http://localhost:3000/ , check for the api readiness using the index route in the browser. You should see a welcome page.

You can access the code in my git repository here.

Written by : Suprith Reddy

I am a serial tech entrepreneur. I believe entrepreneurship is my purpose and technology is my passion. I am naturally business savvy and my expertise is building digital products from scratch and scaling them to create impact. I give talks about technology, business and entrepreneurship.

Subscribe To My Newsletter

BE NOTIFIED ABOUT NEW ARTICLES OR EVENTS OR SESSIONS

Thank you for your message. It has been sent.
There was an error trying to send your message. Please try again later.

You can get access to content with other group of entrepreneurs and startup folks.