smtp4dev configuration can be performed via the appsettings.json file, environment variables and command-line arguments.
✨Many of the basic settings can be edited in the UI
To configure, simply start up smtp4dev and click the settings icon at the top-right of the screen.
When saved, these are written to the settings file at {AppData}/smtp4dev/appsettings.json
You can find the default configuration file at <installlocation>/appsettings.json. This file is included in every release and will be overwritten when you update. To avoid this, create a 'user' configuration file at {AppData}/smtp4dev/appsettings.json and make your customisations there.
{AppData} is platform dependent but normally:
- Windows - environment variable:
APPDATA - Linux & Mac - environment variable:
XDG_CONFIG_HOME
The search path of these files is printed when smtp4dev starts up. So the easiest way to find them is to look there:
smtp4dev version 3.3.6-ci20240419116+60aff5ea69aa19c6fb9afa8573fd5f77ab40de3a
https://github.com/rnwood/smtp4dev
.NET Core runtime version: .NET 8.0.4
> For help use argument --help
Install location: C:\Users\rob
DataDir: C:\Users\rob\AppData\Roaming\smtp4dev
Default settings file: C:\Users\rob\.dotnet\tools\.store\rnwood.smtp4dev\3.3.6-ci20240419116\rnwood.smtp4dev\3.3.6-ci20240419116\tools\net8.0\any\appsettings.json
User settings file: C:\Users\rob\AppData\Roaming\smtp4dev\appsettings.json
Version 3.1.2 onwards will automatically reload and apply any edits to the configuration file without restarting.
Note that this will vary by version of smtp4dev, so for best results, open the settings file you have!
All the values from appsettings.json can be overridden by environment variables.
Set environmment variables in the format: ServerOptions__HostName.
For arrays, use the format ServerOptions__Users__0__User where Users is the property holding the array, 0 is the index of the item and User is one of the properties of that item.
To see the command line options, run Rnwood.Smtp4dev(.exe) or Rnwood.Smtp4dev.Desktop(.exe) with --help.
smtp4dev supports multiple virtual mailboxes to organize incoming messages. This is particularly useful for testing applications that send different types of emails.
- Processing Order: Mailboxes are processed in the order they appear in the configuration
- First Match Wins: Each recipient is matched against mailbox recipient patterns, and the first match determines the destination
- Default Mailbox: A default mailbox with
Recipients="*"(catch-all) is automatically added as the last mailbox - Single Delivery: Each message is delivered only once to each mailbox
- No Duplication: Due to "first match wins" logic, messages go to exactly one mailbox per recipient
Wildcards (recommended for simple patterns):
*@example.com- Any user at example.comuser@*- Specific user at any domain*sales*@*- Any address containing "sales"
Regular Expressions (for complex patterns, surround with /):
/.*@(sales|marketing)\.com$/- Addresses ending with @sales.com or @marketing.com/^(admin|root)@.*$/- Addresses starting with admin@ or root@
{
"ServerOptions": {
"Mailboxes": [
{
"Name": "Sales",
"Recipients": "*@sales.example.com, sales@*"
},
{
"Name": "Support",
"Recipients": "support@*, help@*"
}
]
}
}With this configuration:
john@sales.example.com→ Sales mailbox onlysupport@company.com→ Support mailbox onlyadmin@company.com→ Default mailbox only (no custom match)
{
"ServerOptions": {
"Mailboxes": [
{
"Name": "Spam",
"Recipients": "*spam*@*, *test*@*, *junk*@*"
}
]
}
}With this configuration:
spam-user@example.com→ Spam mailbox onlytest@company.com→ Spam mailbox onlyregular@company.com→ Default mailbox only
If you want to customize the default mailbox behavior, you can explicitly configure it:
{
"ServerOptions": {
"Mailboxes": [
{
"Name": "Alerts",
"Recipients": "*alert*@*, *notification*@*"
},
{
"Name": "Default",
"Recipients": "*"
}
]
}
}Note: Explicitly configuring the default mailbox is typically unnecessary since it's automatically added with the same pattern (*).
-
No Message Duplication: Due to "first match wins" logic, each recipient goes to exactly one mailbox
-
Case Sensitivity: All pattern matching is case-insensitive
-
Multiple Recipients: When an email has multiple recipients, each recipient is processed independently and may go to different mailboxes
-
Authenticated Users: If
DeliverMessagesToUsersDefaultMailboxis enabled and users are authenticated, messages go to the user's configured default mailbox instead of following recipient patterns -
Performance: Wildcard patterns are generally faster than regular expressions for simple matching
Messages not appearing in expected mailbox: Verify the order of mailboxes - earlier mailboxes take precedence over later ones due to "first match wins" logic.
Regex not working: Ensure the pattern is surrounded by forward slashes (/pattern/) and test the regex with an online regex tester.
smtp4dev can output raw message content to stdout for automated processing or testing scenarios. This feature is useful for CI/CD pipelines, automated testing, or integrating with other tools.
Specifies which mailboxes should have their messages output to stdout:
*- Deliver all messages from all mailboxes to stdoutmailbox1,mailbox2- Deliver only messages from specified mailboxes (comma-separated)- Empty string (default) - Disable stdout delivery
Command Line: --delivertostdout="*" or --delivertostdout="Sales,Support"
Configuration File:
{
"ServerOptions": {
"DeliverToStdout": "*"
}
}Automatically exit the application after delivering a specified number of messages to stdout. Useful for automated testing scenarios.
Command Line: --exitafter=5
Configuration File:
{
"ServerOptions": {
"ExitAfterMessages": 5
}
}Messages delivered to stdout are wrapped with delimiters to separate multiple messages:
--- BEGIN SMTP4DEV MESSAGE ---
<raw message content>
--- END SMTP4DEV MESSAGE ---
When using deliver to stdout, all diagnostic and application logs are automatically redirected to stderr, ensuring stdout contains only message content.
Capture all messages and exit after 10:
smtp4dev --delivertostdout="*" --exitafter=10 --smtpport=2525 > messages.txt 2> logs.txtCapture only Sales mailbox messages:
smtp4dev --mailbox="Sales=*sales*@*" --delivertostdout="Sales" --smtpport=2525 > sales-messages.txtUse in CI/CD pipeline:
# Start smtp4dev in background, send test emails, capture output
smtp4dev --delivertostdout="*" --exitafter=3 --smtpport=2525 --imapport=0 --pop3port=0 > captured-emails.txt 2>&1 &
# ... send test emails ...
# Process captured-emails.txtWant messages in multiple mailboxes: This is not supported due to "first match wins" logic. Consider using a single mailbox with multiple recipient patterns instead.