Skip to content

NodeJS service for REST microservices and RabbitMQ messages to send e-mails.

License

Notifications You must be signed in to change notification settings

przybandrzej/mailer-service

Repository files navigation

mailer-service

current version: 0.5.0

A service to send emails from applications from a microservices cluster.
The service takes all emails compatibile with the Nodemailer specification. To see the full Email object, go to API docs.

Known bugs:

  • Swagger API spec causes clients generated by Swagger Codegen CLI to not work with the API. Please use the AMQP protocol (RabbitMQ) to connect to the application.

Getting started

Environment

First we need to create .env file. You can copy the .env.example file.
To start the service (mailer-service) we neeed RabbitMQ and MongoDB instances. You can setup your own local servers or you can use the docker-compose.yml images (recommended).

Start

Dev ::
npm start
Prod ::
npm run prod

Test

npm test

Lint

npm run lint

Setting up mail client

In the .env file add your smtp settings. When using the Nodemailer well-known-services option, set up the MAILER_SERVICE variable, provide the MAILER_USER and MAILER_PASSWORD. That's all. When using normal SMTP connection, provide all the MAIL ENVS except the MAILER_SERVICE.
All the options are equal to the Nodemailer transport options:

  • MAILER_HOST -> host
  • MAILER_PORT -> port
  • MAILER_USER -> auth.user
  • MAILER_PASSWORD -> auth.pass
  • MAILER_SECURE -> secure
  • MAILER_SERVICE -> service

For more info refer to the Nodemailer docs.

Setting up Mongo DB connection

We need to provide connection configuration for Mongo in the .env file. When connecting from inside docker compose (running all 3 services on docker), set mailer_mongo_db (the mongo container name) as the host.

Setting up RabbitMQ connection

We need to provide connection configuration for Rabbit in the .env file. When connecting from inside docker compose (running all 3 services on docker), set rabbit_mq (the rabbitmq container name) as the host.

Tools

Author - Andrzej Przybysz