SERVICES

Mail API Service

Visit Github repository

Mail service

The Mail service is an Email microservice that sends emails using mustache-based templates. It was built to allow our development teams at 2am.tech to avoid having to configure mail over and over on projects involving a microservices infrastructure. It's a combination of two separate applications, one being Symfony's CI application and the other being an API built with Slim3 as it uses a technique called spooling.

The project uses Monolog for logging, Fractal as a serializer, Tactitian as a command bus, gettext for translations, Basic access authentication and Json Web Tokens for authentication (this is optional), and Zend filter for data filtering and validation.

Docker compose and Postman collection files are included for easy development, even though docker is not strictly necessary for development as you could easily use PHP built-in server.

The project tries to follow DDD principles.

Install

Install the latest version using composer.

$ composer create-project --no-interaction --stability=dev 2amigos/mail-service

If you are using it from a private repository (using a github url here as an example).

$ composer create-project --no-interaction --stability=dev 2amigos/mail-service

Sending an email to the filesystem queue

First what we need to do is to modify the commandBus locator map and use the mail.send.queue.handler instead of mail.send.spool.handler:

1$map = [
2	CreateTokenCommand::class => 'token.create.handler',
3	SendMessageCommand::class => 'mail.send.queue.handler',
4];

And that's it. Using the same previous call, this time the message will be sent to folder.

Sending an email from filesystem queue

As we said previously, the php-enqueue/enqueue-bundle comes with a set of pretty handy commands. For the full reference of those commands, please visitits documentation.

The command to consume all the messages that go to the queue is enqueue:consume:

$ ./bin/console enqueue:consume mail --no-interaction -vvv --receive-timeout=60000
Tags: Technology, Design, Computer
Share with

Contributors

Thanks All

tonydspaniard
Terms of Use | Privacy Policy