diff --git a/api/config.go b/api/config.go index 4f32ba1..62c6762 100644 --- a/api/config.go +++ b/api/config.go @@ -26,6 +26,7 @@ func parseConfig() error { "SMTP_USERNAME": "", "SMTP_PASSWORD": "", "SMTP_HOST": "", + "SMTP_PORT": "", "SMTP_FROM_ADDRESS": "", "OAUTH_GOOGLE_KEY": "", diff --git a/api/smtp_configure.go b/api/smtp_configure.go index 779b40b..54a573f 100644 --- a/api/smtp_configure.go +++ b/api/smtp_configure.go @@ -12,7 +12,8 @@ func smtpConfigure() error { username := os.Getenv("SMTP_USERNAME") password := os.Getenv("SMTP_PASSWORD") host := os.Getenv("SMTP_HOST") - if username == "" || password == "" || host == "" { + port := os.Getenv("SMTP_PORT") + if username == "" || password == "" || host == "" || port == "" { logger.Warningf("smtp not configured, no emails will be sent") smtpConfigured = false return nil diff --git a/api/smtp_configure_test.go b/api/smtp_configure_test.go index 3194b84..9cf5c8d 100644 --- a/api/smtp_configure_test.go +++ b/api/smtp_configure_test.go @@ -53,6 +53,7 @@ func TestSmtpConfigureEmptyAddress(t *testing.T) { os.Setenv("SMTP_USERNAME", "test@example.com") os.Setenv("SMTP_PASSWORD", "hunter2") os.Setenv("SMTP_HOST", "smtp.commento.io") + os.Setenv("SMTP_PORT", "25") if err := smtpConfigure(); err == nil { t.Errorf("expected error not found; SMTP should not be configured when SMTP_FROM_ADDRESS is empty") diff --git a/api/smtp_owner_confirm_hex.go b/api/smtp_owner_confirm_hex.go index ffc1454..d143305 100644 --- a/api/smtp_owner_confirm_hex.go +++ b/api/smtp_owner_confirm_hex.go @@ -18,7 +18,7 @@ func smtpOwnerConfirmHex(to string, toName string, confirmHex string) error { var body bytes.Buffer templates["confirm-hex"].Execute(&body, &ownerConfirmHexPlugs{Origin: os.Getenv("ORIGIN"), ConfirmHex: confirmHex}) - err := smtp.SendMail(os.Getenv("SMTP_HOST"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) + err := smtp.SendMail(os.Getenv("SMTP_HOST") + ":" + os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) if err != nil { logger.Errorf("cannot send confirmation email: %v", err) return errorCannotSendEmail diff --git a/api/smtp_owner_reset_hex.go b/api/smtp_owner_reset_hex.go index 3bfaf4f..6dc1f3c 100644 --- a/api/smtp_owner_reset_hex.go +++ b/api/smtp_owner_reset_hex.go @@ -18,7 +18,7 @@ func smtpOwnerResetHex(to string, toName string, resetHex string) error { var body bytes.Buffer templates["reset-hex"].Execute(&body, &ownerResetHexPlugs{Origin: os.Getenv("ORIGIN"), ResetHex: resetHex}) - err := smtp.SendMail(os.Getenv("SMTP_HOST"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) + err := smtp.SendMail(os.Getenv("SMTP_HOST") + ":" + os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) if err != nil { logger.Errorf("cannot send reset email: %v", err) return errorCannotSendEmail