1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-07-05 00:48:52 +02:00

Feature: Add relay config to preserve (keep) original Message-IDs when relaying messages (#515)

This commit is contained in:
Ralph Slooten
2025-06-07 11:38:25 +12:00
parent 6999b2ea02
commit fed20de522
6 changed files with 21 additions and 9 deletions

View File

@ -331,6 +331,7 @@ func initConfigFromEnv() {
config.SMTPRelayConfig.OverrideFrom = os.Getenv("MP_SMTP_RELAY_OVERRIDE_FROM")
config.SMTPRelayConfig.AllowedRecipients = os.Getenv("MP_SMTP_RELAY_ALLOWED_RECIPIENTS")
config.SMTPRelayConfig.BlockedRecipients = os.Getenv("MP_SMTP_RELAY_BLOCKED_RECIPIENTS")
config.SMTPRelayConfig.PreserveMessageIDs = getEnabledFromEnv("MP_SMTP_RELAY_PRESERVE_MESSAGE_IDS")
// SMTP forwarding
config.SMTPForwardConfigFile = os.Getenv("MP_SMTP_FORWARD_CONFIG")

View File

@ -237,6 +237,7 @@ type SMTPRelayConfigStruct struct {
AllowedRecipientsRegexp *regexp.Regexp // compiled regexp using AllowedRecipients
BlockedRecipients string `yaml:"blocked-recipients"` // regex, if set prevents relating to these addresses
BlockedRecipientsRegexp *regexp.Regexp // compiled regexp using BlockedRecipients
PreserveMessageIDs bool `yaml:"preserve-message-ids"` // preserve the original Message-ID when relaying
// DEPRECATED 2024/03/12
RecipientAllowlist string `yaml:"recipient-allowlist"`

View File

@ -62,6 +62,9 @@ type webUIConfiguration struct {
BlockedRecipients string
// Overrides the "From" address for all relayed messages
OverrideFrom string
// Preserve the original Message-IDs when relaying messages
PreserveMessageIDs bool
// DEPRECATED 2024/03/12
// swagger:ignore
RecipientAllowlist string
@ -117,6 +120,8 @@ func WebUIConfig(w http.ResponseWriter, _ *http.Request) {
conf.MessageRelay.AllowedRecipients = config.SMTPRelayConfig.AllowedRecipients
conf.MessageRelay.BlockedRecipients = config.SMTPRelayConfig.BlockedRecipients
conf.MessageRelay.OverrideFrom = config.SMTPRelayConfig.OverrideFrom
conf.MessageRelay.PreserveMessageIDs = config.SMTPRelayConfig.PreserveMessageIDs
// DEPRECATED 2024/03/12
conf.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.AllowedRecipients
}

View File

@ -176,14 +176,15 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) {
return
}
// generate unique ID
if !config.SMTPRelayConfig.PreserveMessageIDs {
// replace the Message-ID header with unique ID
uid := shortuuid.New() + "@mailpit"
// update Message-ID with unique ID
msg, err = tools.SetMessageHeader(msg, "Message-ID", "<"+uid+">")
if err != nil {
httpError(w, err.Error())
return
}
}
if err := smtpd.Relay(from, data.To, msg); err != nil {
logger.Log().Errorf("[smtp] error sending message: %s", err.Error())

View File

@ -140,8 +140,8 @@ export default {
will be rejected:
<code>{{ mailbox.uiConfig.MessageRelay.BlockedRecipients }}</code>
</li>
<li class="form-text">
For testing purposes, a new unique <code>Message-Id</code> will be generated on send.
<li v-if="!mailbox.uiConfig.MessageRelay.PreserveMessageIDs" class="form-text">
For testing purposes, a new unique <code>Message-ID</code> will be generated on send.
</li>
<li v-if="mailbox.uiConfig.MessageRelay.OverrideFrom != ''" class="form-text">
The <code>From</code> email address has been overridden by the relay configuration to

View File

@ -2016,6 +2016,10 @@
"description": "Overrides the \"From\" address for all relayed messages",
"type": "string"
},
"PreserveMessageIDs": {
"description": "Preserve the original Message-IDs when relaying messages",
"type": "boolean"
},
"ReturnPath": {
"description": "Enforced Return-Path (if set) for relay bounces",
"type": "string"