Skip to content

Commit

Permalink
Add support for custom SMTP HELO hostname (for FQDNS)
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 6, 2020
1 parent 047de69 commit 9a88c2e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions config.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 14 additions & 8 deletions messenger/emailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9a88c2e

Please sign in to comment.