[GH-ISSUE #484] Automatic relaying of messages to specific receipiants not working #318

Closed
opened 2026-03-15 13:51:07 +03:00 by kerem · 5 comments
Owner

Originally created by @vendion on GitHub (Apr 28, 2025).
Original GitHub issue: https://github.com/axllent/mailpit/issues/484

Using mailpit v1.24.1 I have SMTP relay setup and can manually release messages and they get successfully delivered. The problem is I want to configure mailpit's automatic relay based on the recipient, I have the MP_SMTP_RELAY_MATCHING environment variable configured and there is no warning in mailpit's logs. The problem is when mailpit receives a message to one or more of the configured addresses it doesn't automatically relay them.

Originally created by @vendion on GitHub (Apr 28, 2025). Original GitHub issue: https://github.com/axllent/mailpit/issues/484 Using mailpit v1.24.1 I have SMTP relay setup and can manually release messages and they get successfully delivered. The problem is I want to configure mailpit's automatic relay based on the recipient, I have the `MP_SMTP_RELAY_MATCHING` environment variable configured and there is no warning in mailpit's logs. The problem is when mailpit receives a message to one or more of the configured addresses it doesn't automatically relay them.
kerem closed this issue 2026-03-15 13:51:12 +03:00
Author
Owner

@axllent commented on GitHub (Apr 29, 2025):

Hi @vendion. Can you please confirm that Mailpit does in fact show that the relay and that the relay-matching is being detected properly? You should get something like this when you start Mailpit in the logs:

INFO[2025/04/29 17:36:49] [relay] enabling message relaying via 10.0.0.2:1025 
INFO[2025/04/29 17:36:49] [relay] auto-relaying new messages to recipients matching "test@test.com" via 10.0.0.2:1025
<!-- gh-comment-id:2837520519 --> @axllent commented on GitHub (Apr 29, 2025): Hi @vendion. Can you please confirm that Mailpit does in fact show that the relay and that the relay-matching is being detected properly? You should get something like this when you **start** Mailpit in the logs: ``` INFO[2025/04/29 17:36:49] [relay] enabling message relaying via 10.0.0.2:1025 INFO[2025/04/29 17:36:49] [relay] auto-relaying new messages to recipients matching "test@test.com" via 10.0.0.2:1025 ```
Author
Owner

@vendion commented on GitHub (May 2, 2025):

On startup, I only get the following:

May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[relay] enabling message relaying via localhost:25"
May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[smtpd] starting on [::]:1025 (no encryption)"
May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[http] starting on [::]:8025"
May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[http] accessible via http://localhost:8025/"

I'm configuring it with the following environment variables defined via SystemD:

Environment="MP_SMTP_RELAY_HOST=localhost"
Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true"
Environment="MP_SMTP_RELAY_ALLOWED_RECIPIENTS='@example\.com$'"
Environment="MP_SMTP_RELAY_MATCHING='(user1|user2)@example\.com$'"
<!-- gh-comment-id:2847002088 --> @vendion commented on GitHub (May 2, 2025): On startup, I only get the following: ``` May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[relay] enabling message relaying via localhost:25" May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[smtpd] starting on [::]:1025 (no encryption)" May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[http] starting on [::]:8025" May 02 06:27:51 rldev8.rowlogic.net mailpit[3099113]: time="2025/05/02 06:27:51" level=info msg="[http] accessible via http://localhost:8025/" ``` I'm configuring it with the following environment variables defined via SystemD: ``` Environment="MP_SMTP_RELAY_HOST=localhost" Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true" Environment="MP_SMTP_RELAY_ALLOWED_RECIPIENTS='@example\.com$'" Environment="MP_SMTP_RELAY_MATCHING='(user1|user2)@example\.com$'" ```
Author
Owner

@axllent commented on GitHub (May 2, 2025):

I really don't understand why it doesn't work on your end, however I suspect it may have something to do with systemd. I note that there also isn't a log entry for the MP_SMTP_RELAY_ALLOWED_RECIPIENTS so I suspect it has something to do with the single quotes within the double quotes.

If I run manually the exact "same" command you're running it detects it fine:

ralph@thinkpad:~$ mailpit version
mailpit v1.24.1 compiled with go1.24.2 on linux/amd64
ralph@thinkpad:~$ MP_SMTP_RELAY_HOST=localhost MP_SMTP_RELAY_ALLOW_INSECURE=true MP_SMTP_RELAY_ALLOWED_RECIPIENTS='@example\.com$' MP_SMTP_RELAY_MATCHING='(user1|user2)@example\.com$' mailpit
INFO[2025/05/02 23:55:59] [relay] recipient allowlist is active with the following regexp: @example\.com$ 
INFO[2025/05/02 23:55:59] [relay] enabling message relaying via localhost:25 
INFO[2025/05/02 23:55:59] [relay] auto-relaying new messages to recipients matching "(user1|user2)@example\.com$" via localhost:25 
INFO[2025/05/02 23:55:59] [smtpd] starting on [::]:1025 (no encryption) 
INFO[2025/05/02 23:55:59] [http] starting on [::]:8025                 
INFO[2025/05/02 23:55:59] [http] accessible via http://localhost:8025/ 

So I'm pretty sure it has to do with the formatting in your systemd config, as neither of those two lines that include both " and ' are getting detected.

Maybe try one of the following:

Environment="MP_SMTP_RELAY_HOST=localhost"
Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true"
Environment=MP_SMTP_RELAY_ALLOWED_RECIPIENTS="@example\.com$"
Environment=MP_SMTP_RELAY_MATCHING="(user1|user2)@example\.com$"

or maybe

Environment="MP_SMTP_RELAY_HOST=localhost"
Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true"
Environment="MP_SMTP_RELAY_ALLOWED_RECIPIENTS=\"@example\.com$\""
Environment="MP_SMTP_RELAY_MATCHING=\"(user1|user2)@example\.com$\""
<!-- gh-comment-id:2847050891 --> @axllent commented on GitHub (May 2, 2025): I really don't understand why it doesn't work on your end, however I suspect it may have something to do with systemd. I note that there also isn't a log entry for the `MP_SMTP_RELAY_ALLOWED_RECIPIENTS` so I suspect it has something to do with the single quotes within the double quotes. If I run manually the exact "same" command you're running it detects it fine: ``` ralph@thinkpad:~$ mailpit version mailpit v1.24.1 compiled with go1.24.2 on linux/amd64 ralph@thinkpad:~$ MP_SMTP_RELAY_HOST=localhost MP_SMTP_RELAY_ALLOW_INSECURE=true MP_SMTP_RELAY_ALLOWED_RECIPIENTS='@example\.com$' MP_SMTP_RELAY_MATCHING='(user1|user2)@example\.com$' mailpit INFO[2025/05/02 23:55:59] [relay] recipient allowlist is active with the following regexp: @example\.com$ INFO[2025/05/02 23:55:59] [relay] enabling message relaying via localhost:25 INFO[2025/05/02 23:55:59] [relay] auto-relaying new messages to recipients matching "(user1|user2)@example\.com$" via localhost:25 INFO[2025/05/02 23:55:59] [smtpd] starting on [::]:1025 (no encryption) INFO[2025/05/02 23:55:59] [http] starting on [::]:8025 INFO[2025/05/02 23:55:59] [http] accessible via http://localhost:8025/ ``` So I'm pretty sure it has to do with the formatting in your systemd config, as neither of those two lines that include both `"` and `'` are getting detected. Maybe try one of the following: ``` Environment="MP_SMTP_RELAY_HOST=localhost" Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true" Environment=MP_SMTP_RELAY_ALLOWED_RECIPIENTS="@example\.com$" Environment=MP_SMTP_RELAY_MATCHING="(user1|user2)@example\.com$" ``` or maybe ``` Environment="MP_SMTP_RELAY_HOST=localhost" Environment="MP_SMTP_RELAY_ALLOW_INSECURE=true" Environment="MP_SMTP_RELAY_ALLOWED_RECIPIENTS=\"@example\.com$\"" Environment="MP_SMTP_RELAY_MATCHING=\"(user1|user2)@example\.com$\"" ```
Author
Owner

@axllent commented on GitHub (May 2, 2025):

You could also look at using EnvironmentFile instead of Environment, or alternatively passing the MP_SMTP_RELAY_ALLOWED_RECIPIENTS and MP_SMTP_RELAY_MATCHING as command flags rather than environment variables in systemd.. Sorry, those two options can't be added as flags. You could however use a yaml config file instead.

I hope this helps.

<!-- gh-comment-id:2847063807 --> @axllent commented on GitHub (May 2, 2025): You could also look at using [EnvironmentFile](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#EnvironmentFile=) instead of Environment, ~~or alternatively passing the `MP_SMTP_RELAY_ALLOWED_RECIPIENTS` and `MP_SMTP_RELAY_MATCHING` as command flags rather than environment variables in systemd.~~. Sorry, those two options can't be added as flags. You could however use a [yaml config](https://mailpit.axllent.org/docs/configuration/smtp-relay/) file instead. I hope this helps.
Author
Owner

@vendion commented on GitHub (May 2, 2025):

Yeah, it seems moving the environment variables to a separate file loaded with EnvironmentFile worked rather than just defining the variables directly in the SystemD service.
Thanks for your help

<!-- gh-comment-id:2847226848 --> @vendion commented on GitHub (May 2, 2025): Yeah, it seems moving the environment variables to a separate file loaded with `EnvironmentFile` worked rather than just defining the variables directly in the SystemD service. Thanks for your help
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#318
No description provided.