Mailer worker is a service which sends emails with Mailgun and offers a variety of scheduling options. This service should be running in background and listen for new emails. In order to use it you have to use your API Key
and Domain
from Mailgun which you will find in your account after a registration. As a next step you need to run mailer-app which is a client application that sends emails to an external storage.
To run the service in background we recommend using forever module.
- Run
npm install forever -g
- you could needsudo
privileges - Clone the repository
git clone git@github.com:shterion/mailer-app.git
- In the root directory run
npm install
to install all dependencies - You should create a
.env
file in the root directory with the following variables:
DB_USERNAME
- your MongoDB usernameDB_PASSWORD
- your MongoDB passwordAPI_KEY
- your MailgunAPI Key
DOMAIN
- your MailgunDomain
APPLICATION_NAME
- application name is only used for a local testing
IMPORTANT: For local testing the
APPLICATION_NAME
variable in mailer-app MUST be the same as this one here. They have to be identical.
- In root directory run
forever start index.js
- The service should be running in background
- To check its status, run
forever list
- To stop it -
forever stopall
The purpose of this service is to listen for new emails, then schedule the new ones and at the end to send them now, later or at certain time in the future with some custom occurrence. Three different modules are responsible for the whole process:
- Cron - its goal is to check if a new email has been stored in the database and if it founds some then it processes it to the next module
- Mailer - Mailgun comes into play to send the emails
- Scheduler - its purpose is to accept the email and schedule it with a certain occurence
To run mailer-worker and mailer-app locally you should have one instance from both of them and they MUST have the same APPLICATION_NAME
.
The application offers the following options for scheduling emails:
- now
- later - on a specific date
- custom occurrence
- repeat - daily, weekly, monthly or yearly
- ends - never, on(date), after(occurrences)