Przeglądaj źródła

feat: Add support for ignoring certs

Dries De Peuter 3 lat temu
rodzic
commit
03d109ff8b
3 zmienionych plików z 12 dodań i 2 usunięć
  1. 1 0
      config.go
  2. 8 2
      smtp.go
  3. 3 0
      smtprelay.ini

+ 1 - 0
config.go

@@ -36,6 +36,7 @@ var (
 	allowedUsers      = flag.String("allowed_users", "", "Path to file with valid users/passwords")
 	command           = flag.String("command", "", "Path to pipe command")
 	remoteHost        = flag.String("remote_host", "", "Outgoing SMTP server")
+	remoteSkipVerify  = flag.Bool("remote_skip_verify", false, "Ignore invalid remote certificates")
 	remoteUser        = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
 	remotePass        = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
 	remoteAuthStr     = flag.String("remote_auth", "none", "Auth method on outgoing SMTP server (none, plain, login)")

+ 8 - 2
smtp.go

@@ -337,7 +337,10 @@ func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
 	}
 	var c *Client
 	if port == "465" || port == "smtps" {
-		config := &tls.Config{ServerName: host}
+		config := &tls.Config{
+			ServerName:         host,
+			InsecureSkipVerify: *remoteSkipVerify,
+		}
 		conn, err := tls.Dial("tcp", addr, config)
 		if err != nil {
 			return err
@@ -360,7 +363,10 @@ func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
 			return err
 		}
 		if ok, _ := c.Extension("STARTTLS"); ok {
-			config := &tls.Config{ServerName: c.serverName}
+			config := &tls.Config{
+				ServerName:         c.serverName,
+				InsecureSkipVerify: *remoteSkipVerify,
+			}
 			if testHookStartTLS != nil {
 				testHookStartTLS(config)
 			}

+ 3 - 0
smtprelay.ini

@@ -68,6 +68,9 @@
 ; Mailjet.com
 ;remote_host = in-v3.mailjet.com:587
 
+; Ignore remote host certificates
+;remote_skip_verify = false
+
 ; Authentication credentials on outgoing SMTP server
 ;remote_user =
 ;remote_pass =