What is a fake SMTP server?

A fake SMTP server accepts SMTP messages but does not transmit emails to external recipients. We use it for development and testing purposes.

Why should we test our emails?

We must test emails to overcome email-related issues like password reset, email links not working, etc.

Why should we set up a fake STMP server for email testing?

Using a dedicated SMTP server is more reliable as we use the same code paths when testing emails using a fake SMTP server to avoid unanticipated problems. How can Gmail as your development email hurt deliverability? Sending the same Gmail inbox several times can impair your email deliverability. Another issue arises when utilizing Gmail addresses on a shared server for test emails.

How to set up a fake SMTP server with smtp4dev?

smtp4 is an open-source fake SMTP server. Install Docker on your machine. For Linux or Windows, download and install a smtp4dev package. We are using Docker to set up smtp4dev for a faster process. Ensure the Docker daemon is running with the command docker info and check the Server: section.

A summary is displayed:

After launching smtp4dev for the first time, an image appears. Docker will download the image from Docker Hub and reuse it:

Guide on each of the Docker options:

• --rm — removes the container when service finishes
• -it — launches the container interactively, streaming its output into the terminal. • -p 3000:80 — map port 80 on a standard HTTP server port to port 3000 on your local machine. The smtp4dev console will be available on http://localhost:3000. • -p 2525:25 — map port 25 in SMTP server port to port 2525 on the machine.

You can visit the application on .

Our server is running on port 2525 using smtp-cli here. You can use any SMTP client, including these libraries in your application:

It shows a working server.

Create a data.txt file with the headers and the body of the email and send: subject: Dragons Either dragons should exist entirely or fail to exist at all, he felt. A dragon only half-existing was worse than the extremes.

Send this email to our fake SMTP server:

After this the email shows up.

Limitations: It is challenging to use smtp4dev for continuous integration. The default setting might not accurately represent what you'll encounter in practice. Try MailSlurps fake smtp servers for a more flexible alternative to SMTP4Dev.