mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
smtp-check: Add a small utility to check SMTP setups
This patch adds a small utility called "smtp-check" that will perform basic checks on the SMTP setup for the given domain. Only basic things are implemented for now.
This commit is contained in:
70
cmd/smtp-check/smtp-check.go
Normal file
70
cmd/smtp-check/smtp-check.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// smtp-check is a command-line too for checking SMTP setups.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/smtp"
|
||||||
|
|
||||||
|
"blitiri.com.ar/go/chasquid/internal/tlsconst"
|
||||||
|
|
||||||
|
"golang.org/x/net/idna"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
port = flag.String("port", "smtp",
|
||||||
|
"port to use for connecting to the MX servers")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
domain := flag.Arg(0)
|
||||||
|
if domain == "" {
|
||||||
|
log.Fatal("Use: smtp-check <domain>")
|
||||||
|
}
|
||||||
|
|
||||||
|
domain, err := idna.ToASCII(domain)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("IDNA conversion failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mxs, err := net.LookupMX(domain)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("MX lookup: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mxs) == 0 {
|
||||||
|
log.Fatalf("MX lookup returned no results")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, mx := range mxs {
|
||||||
|
log.Printf("=== Testing MX: %2d %s", mx.Pref, mx.Host)
|
||||||
|
|
||||||
|
c, err := smtp.Dial(mx.Host + ":" + *port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &tls.Config{
|
||||||
|
// Expect the server to have a certificate valid for the MX
|
||||||
|
// we're connecting to.
|
||||||
|
ServerName: mx.Host,
|
||||||
|
}
|
||||||
|
err = c.StartTLS(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cstate, _ := c.TLSConnectionState()
|
||||||
|
log.Printf("%s - %s", tlsconst.VersionName(cstate.Version),
|
||||||
|
tlsconst.CipherSuiteName(cstate.CipherSuite))
|
||||||
|
|
||||||
|
log.Printf("")
|
||||||
|
c.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("=== Success")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user