Mail Service
Mail service exposes endpoints so other services easily can send emails.
It currently supports sending mail via:
- Sendgrid
- IdRelay
Emails can either be sent in full or by referencing a template in one of those services.
Configure which email service to use by setting SENDGRID_API_KEY
or ID_RELAY_USER_NAME
together with ID_RELAY_PASSWORD
.
Grouping/rate limiting
Mail Service supports rate limiting, or grouping, emails to avoid that a single user for receives the same type emails many time in short period of time.
Lets pretend we are Facebook. We would not like to send a notification every time someone liked your picture (of a cute cat). Instead we would send something like "13 person(s) liked your picture".
This is what grouping email will help you with.
The rate limit and timing is configured by setting env variable GROUPED_MAIL_BATCHES
on syntax:
{numberOfMessages},{timeout};{numberOfMessages},{timeout};
Endpoints
mail-service.send-mail
Sends a mail to one or more mails (emails) addresses
Example request:
{ "from": "i8pNbmZgV@yWjFIbAmZNUitBAmqQnmPKcZtndv.pa", "message": "<h1>Hello</h1> This is the body of the mail!", "subject": "Hello from anywhere else", "templateArgs": "{firstName: \"ola\", lastName: \"bandola\", score: 1337}", "templateId": "5dc78985-ee1f-431d-9266-5eb1a2e7fb96", "to": ["ramjam@frost.se"] }
mail-service.send-grouped-mail
Sends a mail that can be grouped. mails sent using this endpoint will be sent in groups, based off the GROUPED_MAIL_BATCHES
config. mails are grouped by email (taken from the to array) and key.
mail-service.process-grouped-mail-timeouts
To be used by schedule service. Checks for timed out grouped mails. If any is timeout; The pending mails are sent out as one mail and the batch is decreased (Until 0 and then removed).