From e1092d6ceeb528b18d831992aa30fbedcb67bd6d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Jun 2020 15:15:51 -0400 Subject: [PATCH] Fix TLS connection in relayMessageToHost. The host had the port joined, which caused the cert verification to fail. --- smtp/relay.go | 10 +++++----- smtp/relay_test.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/smtp/relay.go b/smtp/relay.go index ae90fe5..713eee9 100644 --- a/smtp/relay.go +++ b/smtp/relay.go @@ -30,16 +30,16 @@ func RelayMessage(server Server, env Envelope, log *zap.Logger) { deliverRelayFailure(server, env, log, rcptTo.Address, "failed to lookup MX records", err) return } - host := mx[0].Host + ":25" - relayMessageToHost(server, env, sendLog, rcptTo.Address, host) + relayMessageToHost(server, env, sendLog, rcptTo.Address, mx[0].Host, "25") } } -func relayMessageToHost(server Server, env Envelope, log *zap.Logger, to, host string) { +func relayMessageToHost(server Server, env Envelope, log *zap.Logger, to, host, port string) { from := env.MailFrom.Address - log = log.With(zap.String("host", host)) + hostPort := net.JoinHostPort(host, port) + log = log.With(zap.String("host", hostPort)) - c, err := smtp.Dial(host) + c, err := smtp.Dial(hostPort) if err != nil { // TODO - retry, or look at other MX records deliverRelayFailure(server, env, log, to, "failed to dial host", err) diff --git a/smtp/relay_test.go b/smtp/relay_test.go index 1934173..175eea5 100644 --- a/smtp/relay_test.go +++ b/smtp/relay_test.go @@ -44,7 +44,8 @@ func TestRelayRoundTrip(t *testing.T) { ID: "ididid", } - relayMessageToHost(s, env, zap.NewNop(), env.RcptTo[0].Address, l.Addr().String()) + host, port, _ := net.SplitHostPort(l.Addr().String()) + relayMessageToHost(s, env, zap.NewNop(), env.RcptTo[0].Address, host, port) if len(s.messages) != 1 { t.Errorf("Expected 1 message to be delivered, got %d", len(s.messages)) -- 2.43.5