From 9a88c2ed7b69bf020ccc95625788017f214a29c3 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Thu, 6 Feb 2020 15:39:43 +0530 Subject: [PATCH] Add support for custom SMTP HELO hostname (for FQDNS) --- config.toml.sample | 5 +++++ go.mod | 2 ++ go.sum | 4 ++++ messenger/emailer.go | 22 ++++++++++++++-------- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/config.toml.sample b/config.toml.sample index 9b29c70..535edd9 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -84,6 +84,11 @@ max_idle = 10 username = "xxxxx" password = "" + # Optional. Some SMTP servers require a FQDN in the hostname. + # By default, HELLOs go with "localhost". Set this if a custom + # hostname should be used. + hello_hostname = "" + # Maximum time (milliseconds) to wait per e-mail push. send_timeout = 5000 diff --git a/go.mod b/go.mod index bb829e4..aa594c9 100644 --- a/go.mod +++ b/go.mod @@ -30,4 +30,6 @@ require ( gopkg.in/volatiletech/null.v6 v6.0.0-20170828023728-0bef4e07ae1b ) +replace github.com/jordan-wright/email => github.com/knadh/email v0.0.0-20200206100304-6d2c7064c2e8 + go 1.13 diff --git a/go.sum b/go.sum index 1096639..65e59ac 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,10 @@ github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jordan-wright/email v0.0.0-20181027021455-480bedc4908b h1:veTPVnbkOijplSJVywDYKDRPoZEN39kfuMDzzRKP0FA= github.com/jordan-wright/email v0.0.0-20181027021455-480bedc4908b/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A= +github.com/knadh/email v0.0.0-20181027021455-480bedc4908b h1:EJPKWXCv9G08Gs5KWjUP8PKj8trrRsLO8B90KZycApE= +github.com/knadh/email v0.0.0-20181027021455-480bedc4908b/go.mod h1:xqJp94kA9qz2ffXuDJueBN+K6MP5BfEGmbIHR8MDJOo= +github.com/knadh/email v0.0.0-20200206100304-6d2c7064c2e8 h1:HVq7nA5uWjpo93WsWjva1YIBuQrr8UkWQEUbzg1DX+E= +github.com/knadh/email v0.0.0-20200206100304-6d2c7064c2e8/go.mod h1:Fy2gCFfZhay8jplf/Csj6cyH/oshQTkLQYZbKkcV+SY= github.com/knadh/goyesql v1.1.1 h1:iQLgsjYI/zC417DhmZYxmJgWmCHhtV4fho5QazWL/1g= github.com/knadh/goyesql v1.1.1/go.mod h1:W0tSzU8l7lYH1Fihj+bdQzkzOwvirrsMNHwkuY22qoY= github.com/knadh/goyesql v2.0.0+incompatible h1:hJFJrU8kaiLmvYt9I/1k1AB7q+qRhHs/afzTfQ3eGqk= diff --git a/messenger/emailer.go b/messenger/emailer.go index 80df9c3..36f1291 100644 --- a/messenger/emailer.go +++ b/messenger/emailer.go @@ -13,14 +13,15 @@ const emName = "email" // Server represents an SMTP server's credentials. type Server struct { - Name string - Host string `koanf:"host"` - Port int `koanf:"port"` - AuthProtocol string `koanf:"auth_protocol"` - Username string `koanf:"username"` - Password string `koanf:"password"` - SendTimeout time.Duration `koanf:"send_timeout"` - MaxConns int `koanf:"max_conns"` + Name string + Host string `koanf:"host"` + Port int `koanf:"port"` + AuthProtocol string `koanf:"auth_protocol"` + Username string `koanf:"username"` + Password string `koanf:"password"` + HelloHostname string `koanf:"hello_hostname"` + SendTimeout time.Duration `koanf:"send_timeout"` + MaxConns int `koanf:"max_conns"` mailer *email.Pool } @@ -52,6 +53,11 @@ func NewEmailer(srv ...Server) (Messenger, error) { return nil, err } + // Optional SMTP HELLO hostname. + if server.HelloHostname != "" { + pool.SetHelloHostname(server.HelloHostname) + } + s.mailer = pool e.servers[s.Name] = &s e.serverNames = append(e.serverNames, s.Name)