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:
- Send bulk emails with cc and bcc
- Fill dynamic content and use custom designed templates
- Can handle array of attachments in the email
- Contains swagger documentation for the request structure
- 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.