Before we start our microservice, we need a working SMTP server. Let's create one with Docker. The following command creates a container with a Postfix server instance:
docker run -it --rm --name test-smtp -p 2525:25
-e SMTP_SERVER=smtp.example.com
-e [email protected]
-e SMTP_PASSWORD=password
-e SERVER_HOSTNAME=smtp.example.com
juanluisbaptiste/postfix
The server exposes port 25 and we remap it to local port 2525. The command sets all the necessary parameters using environment variables and now the mailer microservice is ready to compile and run. Do so using the cargo run command, and when it starts, check it using the following command:
curl -d "[email protected]&code=passcode" -X POST http://localhost:8002/send
When you call this command, the microservice will build and send an email to the Postfix server. Actually, the email won't be delivered, because our mail server works as a relay only and many mail services will reject emails from this kind of mail server. If you want to receive emails, you need to configure the service accordingly.