top of page

How to Setup SMTP Server locally for development environment



Smtp4dev

smtp4dev is a dummy SMTP server for Windows, Linux, Mac OS-X (and maybe elsewhere where .NET Core is available). Lets you test your application without spamming your real customers and without needing to set up a complicated real email server with a special configuration. Messages received in smtp4dev can be viewed and inspected.


It is an ASP.Net core based tool and can be installed on any machine where ASP.Net core is supported.


Docker version

it can be installed as a dotnet tool also, but in this tutorial, I am going to use docker image of smtp4dev.


let’s create container using following cmd.

docker run -p 3000:80 -p 2525:25 -d --name smtpdev rnwood/smtp4dev

Smtp4dev web interface can be accessed on port 3000 and port 2525 used for SMTP .

with this cmd it will not persist the data between container restart.


if you want to persist data between container restart, we need create a volume and map inside the container so that data will be stored in mapped drive.

docker run -p 3000:80 -p 2525:25 -v ./smtp-data:/smtp4dev -d --name smtpdev rnwood/smtp4dev

Open browser and go to http://localhost:3000 to access web interface to test if our container is running successfully and is accessible on given port.

Web interface for smtp4dev


Let’s verify if it receives any email.


Powershell to send mail

For simplicity sake, I am going to use powershell to send mail. you can use any library of your choice for sending the emails.


Open powershell and enter the following command to send mail.

Send-MailMessage -To “test@test.com” -From “admin@test.com”  -Subject “MyMail” -Body “This is the test” -SmtpServer "localhost" -Port "2525"


Checking results in UI

Open browser and go to http://localhost:3000

Web interface smtp4dev with email


We can see the email sent by us.


Summary

We can use this tool to quickly test our email functionality in development without the need of real server.



Source: Medium - Nitesh Singhal


The Tech Platform

0 comments
bottom of page