Browse Source

Merge pull request #16 from decke/discard

Discard mail if remote_host is not set
Bernhard Fröhlich 4 years ago
parent
commit
2475cadbad
3 changed files with 13 additions and 2 deletions
  1. 5 1
      config.go
  2. 6 0
      main.go
  3. 2 1
      smtprelay.ini

+ 5 - 1
config.go

@@ -25,7 +25,7 @@ var (
 	allowedSender     = flag.String("allowed_sender", "", "Regular expression for valid FROM EMail addresses")
 	allowedRecipients = flag.String("allowed_recipients", "", "Regular expression for valid TO EMail addresses")
 	allowedUsers      = flag.String("allowed_users", "", "Path to file with valid users/passwords")
-	remoteHost        = flag.String("remote_host", "smtp.gmail.com:587", "Outgoing SMTP server")
+	remoteHost        = flag.String("remote_host", "", "Outgoing SMTP server")
 	remoteUser        = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
 	remotePass        = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
 	remoteAuth        = flag.String("remote_auth", "plain", "Auth method on outgoing SMTP server (plain, login)")
@@ -38,4 +38,8 @@ func ConfigLoad() {
 
 	// Set up logging as soon as possible
 	setupLogger()
+
+	if (*remoteHost == "") {
+		log.Warn("remote_host not set; mail will not be forwarded!")
+	}
 }

+ 6 - 0
main.go

@@ -180,6 +180,12 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
 		"host": *remoteHost,
 		"uuid": generateUUID(),
 	})
+
+	if (*remoteHost == "") {
+		logger.Warning("remote_host not set; discarding mail")
+		return nil
+	}
+
 	logger.Info("delivering mail from peer using smarthost")
 
 	var auth smtp.Auth

+ 2 - 1
smtprelay.ini

@@ -53,7 +53,8 @@
 ;          E.g. "[email protected],@appsrv.example.com"
 ;allowed_users =
 
-; Relay all mails to this SMTP server
+; Relay all mails to this SMTP server.
+; If not set, mails are discarded.
 
 ; GMail
 ;remote_host = smtp.gmail.com:587