2 min read

Using a local smtp for Sitecore Docker

Short blog post to introduce you to the smtp4dev docker container which we use for local development in our Sitecore Docker setups.

Useful when testing EXM functionality or just when you need to have a mailserver configured in Sitecore.

Taken from the smtp4dev github page:

smtp4dev - the fake SMTP email server for development and testing.

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.

The configuration

The code also contains a docker-compose.yml example and is very easy to setup.

  • First off all, in your /data folder, add an smtp4dev folder and a .gitkeep file.
  • Edit your docker-compose.yml file or the override file. Or better yet, in a dedicated docker-compose for when you need smtp functionality.
    And add the following section:
    image: rnwood/smtp4dev:v3
    restart: always
      # Change the number before : to the port the web interface should be accessible on
      - '5000:80'
      # Change the number before : to the port the SMTP server should be accessible on
      - '25:25'
      # Change the number before : to the port the IMAP server should be accessible on
      - '143:143'
      # This is where smtp4dev stores the database..
        - ${LOCAL_DATA_PATH}\smtp4dev:c:\smtp4dev
      #Specifies the server hostname. Used in auto-generated TLS certificate if enabled.
      - ServerOptions__HostName=smtp4dev
  • You have to define 3 ports, a volume for mounting and the hostname used in the docker containers.
Tip: instead of using the v3 image, I'm using a specific windows version: image: rnwood/smtp4dev:windows-amd64-3.2.0-ci20220809112
Reason behind this is that I had troubles running this container with the latest version in my local Windows 11 environment.

The Sitecore configuration

Add a patch file that uses the smtp4dev server for local development.

Note that we use a custom condition: env:require="Local". Read more about this here: https://doc.sitecore.com/xp/en/developers/102/platform-administration-and-architecture/add-a-custom-rule-to-your-configuration.html

    <exm exmEnabled:require="yes" eds:require="CustomSMTP" role:require="Standalone or ContentManagement or DedicatedDispatch">
            <smtpSettings type="Sitecore.EDS.Core.Net.Smtp.SmtpSettings, Sitecore.EDS.Core" singleInstance="true" env:require="Local">

And that is it, your smtp server is available. Start it with your other containers.

How the webserver looks like

Use the webserver to check the emails that get sent. Use the port that you defined in the yml configuration. http://localhost:5000

You can also download the mails as eml files.

And what is also neat: the mails are saved in database.db in your data folder. So best to add this file to you gitignore list.