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 (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:
$map = [
CreateTokenCommand::class => 'token.create.handler',
SendMessageCommand::class => 'mail.send.queue.handler',
];
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 visit its 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