Skip to content

Commit ad51e5f

Browse files
committed
send emails using a sidecar container with msmtpd
1 parent 6d01f8c commit ad51e5f

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ___
3535
* [Use fail2ban-client](#use-fail2ban-client)
3636
* [Global jail configuration](#global-jail-configuration)
3737
* [Custom jails, actions and filters](#custom-jails-actions-and-filters)
38+
* [Sending email using a sidecar container](#sending-email-using-a-sidecar-container)
3839
* [Contributing](#contributing)
3940
* [License](#license)
4041

@@ -169,7 +170,7 @@ through the container. Here is an example if you want to ban an IP manually:
169170

170171
```console
171172
$ docker exec -t <CONTAINER> fail2ban-client set <JAIL> banip <IP>
172-
```
173+
```
173174

174175
### Global jail configuration
175176

@@ -202,6 +203,12 @@ exists, it will be overriden.
202203
> [!WARNING]
203204
> Container has to be restarted to propagate changes
204205
206+
### Sending email using a sidecar container
207+
208+
If you want to send emails using a sidecar container, see the example in
209+
[examples/smtp](examples/smtp). It uses the [smtp.py action](https://github.com/fail2ban/fail2ban/blob/1.1.0/config/action.d/smtp.py)
210+
and [msmtpd SMTP relay](https://github.com/crazy-max/docker-msmtpd) image.
211+
205212
## Contributing
206213
207214
Want to contribute? Awesome! The most basic way to show your support is to star

examples/smtp/compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: fail2ban
2+
3+
services:
4+
msmtpd:
5+
image: crazymax/msmtpd:latest
6+
container_name: fail2ban_msmtpd
7+
env_file:
8+
- "./msmtpd.env"
9+
ports:
10+
- "127.0.0.1:2500:2500"
11+
environment:
12+
- "TZ"
13+
restart: always
14+
15+
fail2ban:
16+
image: crazymax/fail2ban:latest
17+
container_name: fail2ban
18+
depends_on:
19+
- msmtpd
20+
network_mode: "host"
21+
cap_add:
22+
- NET_ADMIN
23+
- NET_RAW
24+
volumes:
25+
- "./data:/data"
26+
- "/var/log:/var/log:ro"
27+
env_file:
28+
- "./fail2ban.env"
29+
restart: always
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[DEFAULT]
2+
action = smtp.py[host=localhost:2500, sendername=Fail2Ban, sender=foo@gmail.com, dest=foo@gmail.com]

examples/smtp/fail2ban.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TZ=Europe/Paris
2+
3+
F2B_LOG_TARGET=STDOUT
4+
F2B_LOG_LEVEL=INFO
5+
F2B_DB_PURGE_AGE=1d

examples/smtp/msmtpd.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# https://github.com/crazy-max/docker-msmtpd
2+
SMTP_HOST=smtp.gmail.com
3+
SMTP_PORT=587
4+
SMTP_TLS=on
5+
SMTP_STARTTLS=on
6+
SMTP_TLS_CHECKCERT=on
7+
SMTP_AUTH=on
8+
SMTP_USER=foo
9+
SMTP_PASSWORD=bar
10+
SMTP_FROM=foo@gmail.com

0 commit comments

Comments
 (0)