api: add new config SMTP_PORT
This commit is contained in:
parent
9d5e4f9f96
commit
c794c40392
@ -26,6 +26,7 @@ func parseConfig() error {
|
||||
"SMTP_USERNAME": "",
|
||||
"SMTP_PASSWORD": "",
|
||||
"SMTP_HOST": "",
|
||||
"SMTP_PORT": "",
|
||||
"SMTP_FROM_ADDRESS": "",
|
||||
|
||||
"OAUTH_GOOGLE_KEY": "",
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user