git » chasquid » commit ad0dbb9

smtp-check: Add flag to specify local name

author znerol
2023-07-14 17:01:19 UTC
committer Alberto Bertogli
2023-07-16 09:03:50 UTC
parent 9e8452520abbea21e227ccdf7c338d04aa0bb9d7

smtp-check: Add flag to specify local name

Some MTAs reject client connections unless the local name (used in the
HELO/EHLO command) looks like an FQDN. Currently, smtp-check always uses
`localhost`, which does not look like an FQDN.

This patch adds a command line flag to smtp-check to specify the
local name to be used.

Fixes https://github.com/albertito/chasquid/issues/37.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message, adjust flag name, go fmt.

cmd/smtp-check/smtp-check.go +6 -0
docs/man/smtp-check.1 +6 -3
docs/man/smtp-check.1.pod +5 -1

diff --git a/cmd/smtp-check/smtp-check.go b/cmd/smtp-check/smtp-check.go
index dc96146..7bff34d 100644
--- a/cmd/smtp-check/smtp-check.go
+++ b/cmd/smtp-check/smtp-check.go
@@ -25,6 +25,8 @@ import (
 var (
 	port = flag.String("port", "smtp",
 		"port to use for connecting to the MX servers")
+	localName = flag.String("localname", "localhost",
+		"specify the local name for the EHLO command")
 	skipTLSCheck = flag.Bool("skip_tls_check", false,
 		"skip TLS check (useful if connections are blocked)")
 )
@@ -91,6 +93,10 @@ func main() {
 			if err != nil {
 				log.Fatal(err)
 			}
+			err = c.Hello(*localName)
+			if err != nil {
+				log.Fatal(err)
+			}
 
 			config := &tls.Config{
 				// Expect the server to have a certificate valid for the MX
diff --git a/docs/man/smtp-check.1 b/docs/man/smtp-check.1
index d4ad3a4..228b0fe 100644
--- a/docs/man/smtp-check.1
+++ b/docs/man/smtp-check.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
+.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
 .\"
 .\" Standard preamble:
 .\" ========================================================================
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "smtp-check 1"
-.TH smtp-check 1 "2018-04-02" "" ""
+.TH smtp-check 1 "2023-07-16" "" ""
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -142,7 +142,7 @@
 smtp\-check \- SMTP setup checker
 .SH "SYNOPSIS"
 .IX Header "SYNOPSIS"
-\&\fBsmtp-check\fR [\-port \fIport\fR] [\-skip_tls_check] \fIdomain\fR
+\&\fBsmtp-check\fR [\-port \fIport\fR] [\-localname \fIdomain\fR] [\-skip_tls_check] \fIdomain\fR
 .SH "DESCRIPTION"
 .IX Header "DESCRIPTION"
 smtp-check is a command-line too for checking \s-1SMTP\s0 setups (\s-1DNS\s0 records, \s-1TLS\s0
@@ -152,6 +152,9 @@ certificates, \s-1SPF,\s0 etc.).
 .IP "\fB\-port\fR \fIport\fR:" 8
 .IX Item "-port port:"
 Port to use for connecting to the \s-1MX\s0 servers.
+.IP "\fB\-localname\fR \fIdomain\fR:" 8
+.IX Item "-localname domain:"
+Local name to use for the \s-1EHLO\s0 command.
 .IP "\fB\-skip_tls_check\fR:" 8
 .IX Item "-skip_tls_check:"
 Skip \s-1TLS\s0 check (useful if connections are blocked).
diff --git a/docs/man/smtp-check.1.pod b/docs/man/smtp-check.1.pod
index a35eaec..6246282 100644
--- a/docs/man/smtp-check.1.pod
+++ b/docs/man/smtp-check.1.pod
@@ -4,7 +4,7 @@ smtp-check - SMTP setup checker
 
 =head1 SYNOPSIS
 
-B<smtp-check> [-port I<port>] [-skip_tls_check] I<domain>
+B<smtp-check> [-port I<port>] [-localname I<domain>] [-skip_tls_check] I<domain>
 
 =head1 DESCRIPTION
 
@@ -19,6 +19,10 @@ certificates, SPF, etc.).
 
 Port to use for connecting to the MX servers.
 
+=item B<-localname> I<domain>:
+
+Local name to use for the EHLO command.
+
 =item B<-skip_tls_check>:
 
 Skip TLS check (useful if connections are blocked).