A simple, lightweight SMTP server that receives emails and forwards them as direct messages to Slack users. It's designed to be a simple bridge for applications that can only send notifications via email, allowing them to post messages to Slack instead.
- Acts as a standard SMTP server.
- Parses incoming emails for sender, recipients, subject, and body.
- Forwards formatted messages as direct messages to Slack users, looking them up by the recipient email address.
- Supports optional SMTP
PLAINauthentication. - Filters sender and recipient addresses using flexible allow/deny lists.
The server is configured using a YAML file (e.g., config.yaml). The file has two main sections: smtp, and slack.
smtp:
listen-addr: "0.0.0.0:1025"
auth:
enabled: true
user-database: "/etc/go-smtp-slacker/users.db"
policies:
from:
default-action: "deny" # "allow" or "deny"
allow:
- "alerts@example.com"
- "monitoring-?@my-domain.com"
deny:
- "*@spam.com"
to:
default-action: "allow"
allow:
- "*"
deny:
- "ignored@example.com"
slack:
token: "xoxb-your-slack-bot-token"This section configures the core SMTP server.
addr: The IP address and port the server should listen on. Use0.0.0.0to listen on all network interfaces.prefer-html-body: Set totrueto use the HTML body from email, if available, otherwise use plain text.
This section controls SMTP authentication. When enabled, clients must authenticate before they can send an email.
enabled: Set totrueto require client authentication. Iffalse, the server will operate as an open relay (though still subject to policy restrictions).user-database: The absolute path to the user database file. This file contains the usernames and their corresponding bcrypt-hashed passwords.
The user database is a simple text file where each line represents a user in the format username:bcrypt_hash. Lines starting with # are treated as comments and are ignored.
Example users.db:
# User for our monitoring system
monitoring:$2a$10$abcdefghijklmnopqrstuv.abcdefghijklmnopqrstuv.abcdefghij
You can generate a bcrypt hash for a password using various tools. For example, with htpasswd (from Apache utils):
# Install apache2-utils if you don't have it
# Debian/Ubuntu: sudo apt-get install apache2-utils
# CentOS/RHEL: sudo dnf install httpd-tools
htpasswd -B -n newuser
# The command will ask you for a password and will output something like:
# newuser:$2y$10$P.gL4v2hergM3sU3B5t25eRzWpE7YzzHSHx4xX3jXyS.i3cZz3n.O
#
# Copy the output into your users.db file.Policies allow you to control which emails are accepted based on sender (from) and recipient (to) addresses. This is useful for preventing unauthorized use.
Rules are processed in this order:
- If an address matches a pattern in the
denylist, it is rejected. - If an address matches a pattern in the
allowlist, it is accepted. - If an address matches no patterns, the
default-actionis applied.
Fields:
default-action: Determines the behavior for an address that does not match anyallowordenypatterns. Can beallowordeny.allow: A list of glob patterns. Addresses matching these patterns are allowed.deny: A list of glob patterns. Addresses matching these patterns are denied.
Glob Patterns: The matching is case-insensitive.
*: Matches any sequence of characters.?: Matches any single character.
Example:
*@example.commatches any user atexample.com.user-?@domain.commatchesuser-1@domain.com,user-a@domain.com, etc.
This section configures the Slack integration.
token: The Slack Bot User OAuth Token for your Slack app. It usually starts withxoxb-. This is a required field. It can be set via theSLACK_TOKENenvironment variable or a file specified with--slack.token-file.
Flags can be used to override settings from the configuration file.
| Flag | Shorthand | Description | Default |
|---|---|---|---|
--config-file |
The path to look for the configuration file (config.yaml). |
./config.yaml |
|
--log-level |
The log level to use. | INFO |
|
--smtp.listen-addr |
Listen address for the SMTP server. | localhost:25 |
|
--smtp.auth.enabled |
-a |
Enable SMTP authentication. | false |
--smtp.auth.user-database |
Path to the user database file. | ||
--smtp.prefer-html-body |
Use HTML from email, if available, otherwise use plain text | true |
|
--slack.token-file |
The path to a file containing the Slack token. | ||
--help |
-h |
Prints this help message. | |
--version |
-V |
Prints the version. |
A few key settings can be provided via environment variables for convenience, especially in containerized environments.
| Variable | Description |
|---|---|
LOG_LEVEL |
Overrides the log-level configuration. |
SLACK_TOKEN |
Overrides the slack.token configuration. This is the most common way to provide the token securely. |