mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 16:52:29 -07:00
make possible #91.
- add strict_sender bool configuration value - if strict_sender set as true use for outgoing mail only SMTPs with sender matches to from address
This commit is contained in:
@@ -45,6 +45,7 @@ var (
|
|||||||
allowedUsers = flagset.String("allowed_users", "", "Path to file with valid users/passwords")
|
allowedUsers = flagset.String("allowed_users", "", "Path to file with valid users/passwords")
|
||||||
command = flagset.String("command", "", "Path to pipe command")
|
command = flagset.String("command", "", "Path to pipe command")
|
||||||
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
|
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
|
||||||
|
strictSender = flagset.Bool("strict_sender", false, "Use only SMTP servers with Sender matches to From")
|
||||||
|
|
||||||
// additional flags
|
// additional flags
|
||||||
_ = flagset.String("config", "", "Path to config file (ini format)")
|
_ = flagset.String("config", "", "Path to config file (ini format)")
|
||||||
|
|||||||
18
main.go
18
main.go
@@ -163,9 +163,21 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
"uuid": generateUUID(),
|
"uuid": generateUUID(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if *remotesStr == "" && *command == "" {
|
var envRemotes []*Remote
|
||||||
|
|
||||||
|
if *strictSender {
|
||||||
|
for _, remote := range remotes {
|
||||||
|
if remote.Sender == env.Sender {
|
||||||
|
envRemotes = append(envRemotes, remote)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
envRemotes = remotes
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(envRemotes) == 0 && *command == "" {
|
||||||
logger.Warning("no remote_host or command set; discarding mail")
|
logger.Warning("no remote_host or command set; discarding mail")
|
||||||
return nil
|
return smtpd.Error{Code: 554, Message: "There are no appropriate remote_host or command"}
|
||||||
}
|
}
|
||||||
|
|
||||||
env.AddReceivedLine(peer)
|
env.AddReceivedLine(peer)
|
||||||
@@ -190,7 +202,7 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
cmdLogger.Info("pipe command successful: " + stdout.String())
|
cmdLogger.Info("pipe command successful: " + stdout.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, remote := range remotes {
|
for _, remote := range envRemotes {
|
||||||
logger = logger.WithField("host", remote.Addr)
|
logger = logger.WithField("host", remote.Addr)
|
||||||
logger.Info("delivering mail from peer using smarthost")
|
logger.Info("delivering mail from peer using smarthost")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user