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.


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 (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.
// 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.

Related Articles