[BUGFIX] Add ability to specify SMTP HELO/EHLO identifier (#1416)

* add docs
* add configuration option for SMTP called `identifier`
* default should act the same as before
This commit is contained in:
James Elliott 2020-11-05 10:22:10 +11:00 committed by GitHub
parent 898cfbd206
commit 956dbfb8de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 1 deletions

View File

@ -400,6 +400,8 @@ notifier:
host: 127.0.0.1
port: 1025
sender: admin@example.com
# HELO/EHLO Identifier. Some SMTP Servers may reject the default of localhost.
identifier: localhost
# Subject configuration of the emails sent.
# {title} is replaced by the text from the notifier
subject: "[Authelia] {title}"

View File

@ -43,6 +43,8 @@ notifier:
host: 127.0.0.1
port: 1025
sender: admin@example.com
# HELO/EHLO Identifier. Some SMTP Servers may reject the default of localhost.
identifier: localhost
# Subject configuration of the emails sent.
# {title} is replaced by the text from the notifier
subject: "[Authelia] {title}"
@ -59,6 +61,10 @@ notifier:
Most configuration options are self-explanatory, however here is an explanation of the ones that may not
be as obvious.
### identifier
The name to send to the SMTP server as the identifier with the HELO/EHLO command. Some SMTP providers like Google Mail
reject the message if it's localhost.
### subject
This is the subject Authelia will use in the email, it has a single placeholder at present `{title}` which should
be included in all emails as it is the internal descriptor for the contents of the email.

View File

@ -11,6 +11,7 @@ type SMTPNotifierConfiguration struct {
Port int `mapstructure:"port"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Identifier string `mapstructure:"identifier"`
Sender string `mapstructure:"sender"`
Subject string `mapstructure:"subject"`
TrustedCert string `mapstructure:"trusted_cert"`
@ -29,5 +30,6 @@ type NotifierConfiguration struct {
// DefaultSMTPNotifierConfiguration represents default configuration parameters for the SMTP notifier.
var DefaultSMTPNotifierConfiguration = SMTPNotifierConfiguration{
Subject: "[Authelia] {title}",
Subject: "[Authelia] {title}",
Identifier: "localhost",
}

View File

@ -66,6 +66,7 @@ var validKeys = []string{
"notifier.smtp.password",
"notifier.smtp.host",
"notifier.smtp.port",
"notifier.smtp.identifier",
"notifier.smtp.sender",
"notifier.smtp.subject",
"notifier.smtp.startup_check_address",

View File

@ -47,6 +47,10 @@ func ValidateNotifier(configuration *schema.NotifierConfiguration, validator *sc
configuration.SMTP.Subject = schema.DefaultSMTPNotifierConfiguration.Subject
}
if configuration.SMTP.Identifier == "" {
configuration.SMTP.Identifier = schema.DefaultSMTPNotifierConfiguration.Identifier
}
return
}
}

View File

@ -21,6 +21,7 @@ type SMTPNotifier struct {
username string
password string
sender string
identifier string
host string
port int
trustedCert string
@ -39,6 +40,7 @@ func NewSMTPNotifier(configuration schema.SMTPNotifierConfiguration) *SMTPNotifi
username: configuration.Username,
password: configuration.Password,
sender: configuration.Sender,
identifier: configuration.Identifier,
host: configuration.Host,
port: configuration.Port,
trustedCert: configuration.TrustedCert,
@ -277,6 +279,10 @@ func (n *SMTPNotifier) StartupCheck() (bool, error) {
defer n.cleanup()
if err := n.client.Hello(n.identifier); err != nil {
return false, err
}
if err := n.startTLS(); err != nil {
return false, err
}
@ -311,6 +317,10 @@ func (n *SMTPNotifier) Send(recipient, title, body, htmlBody string) error {
// Always execute QUIT at the end once we're connected.
defer n.cleanup()
if err := n.client.Hello(n.identifier); err != nil {
return err
}
// Start TLS and then Authenticate.
if err := n.startTLS(); err != nil {
return err