Skip to content

Commit

Permalink
improve treatment of default SMTP port
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Oct 25, 2023
1 parent 4fdd37c commit 0bf9abe
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func main() {
fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable.", SMTPPassEnvVar))
smtpHost := flag.String("smtp-host", "", "SMTP server hostname. "+
fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable.", SMTPHostEnvVar))
smtpPort := flag.Int("smtp-port", 0, "SMTP server port. "+
fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable. (default: 25)", SMTPPortEnvVar))
smtpPort := flag.Int("smtp-port", 25, "SMTP server port. "+
fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable.", SMTPPortEnvVar))
mailTabCharReplacement := flag.String("mail-tab-char", "", "Replace tab characters in emailed output by this string. "+
fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable.", MailTabCharEnvVar))

Expand Down Expand Up @@ -269,13 +269,11 @@ func main() {
if mailCfg.tabCharReplacement == "" {
mailCfg.tabCharReplacement = os.Getenv(MailTabCharEnvVar)
}
if mailCfg.smtpPort == 0 {
if os.Getenv(SMTPPortEnvVar) != "" && !WasFlagGiven("smtp-port") {
smtpPortStr := os.Getenv(SMTPPortEnvVar)
if smtpPortStr != "" {
mailCfg.smtpPort, err = strconv.Atoi(smtpPortStr)
if err != nil {
log.Fatalf("Failed to parse %s ('%s') as integer: %s", SMTPPortEnvVar, smtpPortStr, err)
}
mailCfg.smtpPort, err = strconv.Atoi(smtpPortStr)
if err != nil {
log.Fatalf("Failed to parse %s ('%s') as integer: %s", SMTPPortEnvVar, smtpPortStr, err)
}
}
if mailCfg.mailTo != "" && strings.Contains(mailCfg.mailTo, "@") {
Expand Down

0 comments on commit 0bf9abe

Please sign in to comment.