Allow separate SMTP TLS server name
This commit is contained in:
@@ -22,6 +22,7 @@ Recommended settings:
|
|||||||
- `SMTP_PORT=587`
|
- `SMTP_PORT=587`
|
||||||
- `SMTP_STARTTLS=true`
|
- `SMTP_STARTTLS=true`
|
||||||
- `SMTP_HELO_NAME=mailer.example.invalid`
|
- `SMTP_HELO_NAME=mailer.example.invalid`
|
||||||
|
- `SMTP_TLS_SERVER_NAME=smtp.example.invalid`
|
||||||
- `SMTP_USERNAME`
|
- `SMTP_USERNAME`
|
||||||
- `SMTP_PASSWORD`
|
- `SMTP_PASSWORD`
|
||||||
- `PRINT_REPORT=true`
|
- `PRINT_REPORT=true`
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ type Config struct {
|
|||||||
SMTPPassword string
|
SMTPPassword string
|
||||||
SMTPStartTLS bool
|
SMTPStartTLS bool
|
||||||
SMTPHeloName string
|
SMTPHeloName string
|
||||||
|
SMTPTLSServer string
|
||||||
EmailFrom string
|
EmailFrom string
|
||||||
EmailTo []string
|
EmailTo []string
|
||||||
PrintReport bool
|
PrintReport bool
|
||||||
@@ -177,6 +178,10 @@ func loadConfig() (Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Config{}, err
|
return Config{}, err
|
||||||
}
|
}
|
||||||
|
smtpTLSServer, err := readValue("SMTP_TLS_SERVER_NAME", "", false)
|
||||||
|
if err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
emailFrom, err := readValue("EMAIL_FROM", "", false)
|
emailFrom, err := readValue("EMAIL_FROM", "", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Config{}, err
|
return Config{}, err
|
||||||
@@ -210,6 +215,7 @@ func loadConfig() (Config, error) {
|
|||||||
SMTPPassword: smtpPassword,
|
SMTPPassword: smtpPassword,
|
||||||
SMTPStartTLS: smtpStartTLS,
|
SMTPStartTLS: smtpStartTLS,
|
||||||
SMTPHeloName: normalizeSMTPHeloName(smtpHeloName),
|
SMTPHeloName: normalizeSMTPHeloName(smtpHeloName),
|
||||||
|
SMTPTLSServer: strings.TrimSpace(smtpTLSServer),
|
||||||
EmailFrom: emailFrom,
|
EmailFrom: emailFrom,
|
||||||
EmailTo: emailTo,
|
EmailTo: emailTo,
|
||||||
PrintReport: printReport,
|
PrintReport: printReport,
|
||||||
@@ -601,12 +607,13 @@ func sendEmail(cfg Config, subject, body string) error {
|
|||||||
|
|
||||||
host := cfg.SMTPHost
|
host := cfg.SMTPHost
|
||||||
heloName := normalizeSMTPHeloName(cfg.SMTPHeloName)
|
heloName := normalizeSMTPHeloName(cfg.SMTPHeloName)
|
||||||
|
tlsServerName := firstNonEmpty(cfg.SMTPTLSServer, host)
|
||||||
if err := conn.Hello(heloName); err != nil {
|
if err := conn.Hello(heloName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if cfg.SMTPStartTLS {
|
if cfg.SMTPStartTLS {
|
||||||
if ok, _ := conn.Extension("STARTTLS"); ok {
|
if ok, _ := conn.Extension("STARTTLS"); ok {
|
||||||
if err := conn.StartTLS(&tls.Config{ServerName: host, MinVersion: tls.VersionTLS12}); err != nil {
|
if err := conn.StartTLS(&tls.Config{ServerName: tlsServerName, MinVersion: tls.VersionTLS12}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := conn.Hello(heloName); err != nil {
|
if err := conn.Hello(heloName); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user