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:
@ -331,6 +331,7 @@ func initConfigFromEnv() {
|
|||||||
config.SMTPRelayConfig.OverrideFrom = os.Getenv("MP_SMTP_RELAY_OVERRIDE_FROM")
|
config.SMTPRelayConfig.OverrideFrom = os.Getenv("MP_SMTP_RELAY_OVERRIDE_FROM")
|
||||||
config.SMTPRelayConfig.AllowedRecipients = os.Getenv("MP_SMTP_RELAY_ALLOWED_RECIPIENTS")
|
config.SMTPRelayConfig.AllowedRecipients = os.Getenv("MP_SMTP_RELAY_ALLOWED_RECIPIENTS")
|
||||||
config.SMTPRelayConfig.BlockedRecipients = os.Getenv("MP_SMTP_RELAY_BLOCKED_RECIPIENTS")
|
config.SMTPRelayConfig.BlockedRecipients = os.Getenv("MP_SMTP_RELAY_BLOCKED_RECIPIENTS")
|
||||||
|
config.SMTPRelayConfig.PreserveMessageIDs = getEnabledFromEnv("MP_SMTP_RELAY_PRESERVE_MESSAGE_IDS")
|
||||||
|
|
||||||
// SMTP forwarding
|
// SMTP forwarding
|
||||||
config.SMTPForwardConfigFile = os.Getenv("MP_SMTP_FORWARD_CONFIG")
|
config.SMTPForwardConfigFile = os.Getenv("MP_SMTP_FORWARD_CONFIG")
|
||||||
|
@ -237,6 +237,7 @@ type SMTPRelayConfigStruct struct {
|
|||||||
AllowedRecipientsRegexp *regexp.Regexp // compiled regexp using AllowedRecipients
|
AllowedRecipientsRegexp *regexp.Regexp // compiled regexp using AllowedRecipients
|
||||||
BlockedRecipients string `yaml:"blocked-recipients"` // regex, if set prevents relating to these addresses
|
BlockedRecipients string `yaml:"blocked-recipients"` // regex, if set prevents relating to these addresses
|
||||||
BlockedRecipientsRegexp *regexp.Regexp // compiled regexp using BlockedRecipients
|
BlockedRecipientsRegexp *regexp.Regexp // compiled regexp using BlockedRecipients
|
||||||
|
PreserveMessageIDs bool `yaml:"preserve-message-ids"` // preserve the original Message-ID when relaying
|
||||||
|
|
||||||
// DEPRECATED 2024/03/12
|
// DEPRECATED 2024/03/12
|
||||||
RecipientAllowlist string `yaml:"recipient-allowlist"`
|
RecipientAllowlist string `yaml:"recipient-allowlist"`
|
||||||
|
@ -62,6 +62,9 @@ type webUIConfiguration struct {
|
|||||||
BlockedRecipients string
|
BlockedRecipients string
|
||||||
// Overrides the "From" address for all relayed messages
|
// Overrides the "From" address for all relayed messages
|
||||||
OverrideFrom string
|
OverrideFrom string
|
||||||
|
// Preserve the original Message-IDs when relaying messages
|
||||||
|
PreserveMessageIDs bool
|
||||||
|
|
||||||
// DEPRECATED 2024/03/12
|
// DEPRECATED 2024/03/12
|
||||||
// swagger:ignore
|
// swagger:ignore
|
||||||
RecipientAllowlist string
|
RecipientAllowlist string
|
||||||
@ -117,6 +120,8 @@ func WebUIConfig(w http.ResponseWriter, _ *http.Request) {
|
|||||||
conf.MessageRelay.AllowedRecipients = config.SMTPRelayConfig.AllowedRecipients
|
conf.MessageRelay.AllowedRecipients = config.SMTPRelayConfig.AllowedRecipients
|
||||||
conf.MessageRelay.BlockedRecipients = config.SMTPRelayConfig.BlockedRecipients
|
conf.MessageRelay.BlockedRecipients = config.SMTPRelayConfig.BlockedRecipients
|
||||||
conf.MessageRelay.OverrideFrom = config.SMTPRelayConfig.OverrideFrom
|
conf.MessageRelay.OverrideFrom = config.SMTPRelayConfig.OverrideFrom
|
||||||
|
conf.MessageRelay.PreserveMessageIDs = config.SMTPRelayConfig.PreserveMessageIDs
|
||||||
|
|
||||||
// DEPRECATED 2024/03/12
|
// DEPRECATED 2024/03/12
|
||||||
conf.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.AllowedRecipients
|
conf.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.AllowedRecipients
|
||||||
}
|
}
|
||||||
|
@ -176,13 +176,14 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate unique ID
|
if !config.SMTPRelayConfig.PreserveMessageIDs {
|
||||||
uid := shortuuid.New() + "@mailpit"
|
// replace the Message-ID header with unique ID
|
||||||
// update Message-ID with unique ID
|
uid := shortuuid.New() + "@mailpit"
|
||||||
msg, err = tools.SetMessageHeader(msg, "Message-ID", "<"+uid+">")
|
msg, err = tools.SetMessageHeader(msg, "Message-ID", "<"+uid+">")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err.Error())
|
httpError(w, err.Error())
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := smtpd.Relay(from, data.To, msg); err != nil {
|
if err := smtpd.Relay(from, data.To, msg); err != nil {
|
||||||
|
@ -140,8 +140,8 @@ export default {
|
|||||||
will be rejected:
|
will be rejected:
|
||||||
<code>{{ mailbox.uiConfig.MessageRelay.BlockedRecipients }}</code>
|
<code>{{ mailbox.uiConfig.MessageRelay.BlockedRecipients }}</code>
|
||||||
</li>
|
</li>
|
||||||
<li class="form-text">
|
<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.
|
For testing purposes, a new unique <code>Message-ID</code> will be generated on send.
|
||||||
</li>
|
</li>
|
||||||
<li v-if="mailbox.uiConfig.MessageRelay.OverrideFrom != ''" class="form-text">
|
<li v-if="mailbox.uiConfig.MessageRelay.OverrideFrom != ''" class="form-text">
|
||||||
The <code>From</code> email address has been overridden by the relay configuration to
|
The <code>From</code> email address has been overridden by the relay configuration to
|
||||||
|
@ -2016,6 +2016,10 @@
|
|||||||
"description": "Overrides the \"From\" address for all relayed messages",
|
"description": "Overrides the \"From\" address for all relayed messages",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"PreserveMessageIDs": {
|
||||||
|
"description": "Preserve the original Message-IDs when relaying messages",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"ReturnPath": {
|
"ReturnPath": {
|
||||||
"description": "Enforced Return-Path (if set) for relay bounces",
|
"description": "Enforced Return-Path (if set) for relay bounces",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
Reference in New Issue
Block a user