Simple SMTP Server which stores all received emails in an in-memory database and renders the emails in a web interface
The Fake SMTP Server is a simple SMTP server which is designed for development purposes. The server collects all received emails, stores the emails in an in-memory database and provides access to the emails via a web interface.
There is no POP3 or IMAP interface included by intention. The basic idea of this software is that it is used during development to configure the server as target mail server. Instead of sending the emails to a real SMTP server which would forward the mails to the target recipient or return with mail undelivery for test email addresses (e.g. @example.com) the server just accepts all mails, stores them in the database so that they can be rendered in the UI. This allows you to use any test mail address and check the sent email in the web application of the Fake SMTP Server.
The server store a configurable maximum number of emails. If the maximum number of emails is exceeded old emails will be deleted to avoid that the system consumes too much memory.
The server is also provided as docker image on docker hub gessnerfl/fake-smtp-server. To change configuration parameters the corresponding configuration values have to be specified as environment variables for the docker container. For details check the Spring Boot (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config) and docker documentation (https://docs.docker.com/engine/reference/run/#env-environment-variables).
Note: You need Java 11 installed to run Fake SMTP Server.
- Download the latest
fake-smtp-server-<version>.jar
from https://github.com/gessnerfl/fake-smtp-server/releases/latest - Copy the file into the desired target folder
- Execute the following command from the folder where the JAR file is located:
java -jar fake-smtp-server-<version>.jar
In order to run this application locally from sources, execute:
./gradlew bootRun
Afterwards, the web interface is be availabe under http://localhost:5080.
As the application is based on Spring Boot the same rules applies to the configuration as described in the Spring Boot Documentation (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config).
The configuration file application.yaml can be placed next to the application jar, in a sub-directory config or
in any other location when specifying the location with the parameter -Dspring.config.location=<path to config file>
.
The following paragraphs describe the application specific resp. pre-defined configuration parameters.
The following snippet shows the configuration of a fake smtp server with its default values.
fakesmtp:
#The SMTP Server Port used by the Fake SMTP Server
port: 5025
#The binding address of the Fake SMTP Server; Bound to all interfaces by default / no value
bindAddress: 127.0.0.1
persistence:
#The maximum number of emails which should be stored in the database; Defualts to 100
maxNumberEmails: 100
#List of recipient addresses which should be blocked/rejected
blockedRecipientAddresses:
- blocked@example.com
- foo@eample.com
#List of sender email addresses to ignore, as a comma-separated list of regex expressions.
filteredEmailRegexList: john@doe\\.com,.*@google\\.com ; empty by default
#Optional configuration option to specify the maximum allowed message size. The size can be
#defined using Spring Boot DataSize value type - https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-conversion-datasize.
#Default: no limit
maxMessageSize: 10MB
#Configure if TLS is required to connect to the SMTP server. Defaults to false
requireTLS: false
#When set to true emails will be forwarded to a configured target email system. Therefore
#the spring boot mail system needs to be configured. See also
# https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-email
forwardEmails: false
Optionally authentication can be turned on. Configuring authentication does not mean the authentication is enforced. It just allows you to test PLAIN and LOGIN SMTP Authentication against the server instance.
fakesmpt:
authentication:
#Username of the client to be authenticated
username: myuser
#Password of the client to be authenticated
password: mysecretpassword
The following snippet shows the pre-defined web application configuration
#Port of the web interface
server:
port: 5080
#Port of the http management api
management:
server:
port: 5081
Documentation of exposed services is available at:
localhost:5080/swagger-ui.html