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