api: add new config SMTP_PORT

This commit is contained in:
Adhityaa 2018-06-09 15:22:49 +05:30
parent 9d5e4f9f96
commit c794c40392
5 changed files with 6 additions and 3 deletions

View File

@ -26,6 +26,7 @@ func parseConfig() error {
"SMTP_USERNAME": "", "SMTP_USERNAME": "",
"SMTP_PASSWORD": "", "SMTP_PASSWORD": "",
"SMTP_HOST": "", "SMTP_HOST": "",
"SMTP_PORT": "",
"SMTP_FROM_ADDRESS": "", "SMTP_FROM_ADDRESS": "",
"OAUTH_GOOGLE_KEY": "", "OAUTH_GOOGLE_KEY": "",

View File

@ -12,7 +12,8 @@ func smtpConfigure() error {
username := os.Getenv("SMTP_USERNAME") username := os.Getenv("SMTP_USERNAME")
password := os.Getenv("SMTP_PASSWORD") password := os.Getenv("SMTP_PASSWORD")
host := os.Getenv("SMTP_HOST") 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") logger.Warningf("smtp not configured, no emails will be sent")
smtpConfigured = false smtpConfigured = false
return nil return nil

View File

@ -53,6 +53,7 @@ func TestSmtpConfigureEmptyAddress(t *testing.T) {
os.Setenv("SMTP_USERNAME", "test@example.com") os.Setenv("SMTP_USERNAME", "test@example.com")
os.Setenv("SMTP_PASSWORD", "hunter2") os.Setenv("SMTP_PASSWORD", "hunter2")
os.Setenv("SMTP_HOST", "smtp.commento.io") os.Setenv("SMTP_HOST", "smtp.commento.io")
os.Setenv("SMTP_PORT", "25")
if err := smtpConfigure(); err == nil { if err := smtpConfigure(); err == nil {
t.Errorf("expected error not found; SMTP should not be configured when SMTP_FROM_ADDRESS is empty") t.Errorf("expected error not found; SMTP should not be configured when SMTP_FROM_ADDRESS is empty")

View File

@ -18,7 +18,7 @@ func smtpOwnerConfirmHex(to string, toName string, confirmHex string) error {
var body bytes.Buffer var body bytes.Buffer
templates["confirm-hex"].Execute(&body, &ownerConfirmHexPlugs{Origin: os.Getenv("ORIGIN"), ConfirmHex: confirmHex}) 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 { if err != nil {
logger.Errorf("cannot send confirmation email: %v", err) logger.Errorf("cannot send confirmation email: %v", err)
return errorCannotSendEmail return errorCannotSendEmail

View File

@ -18,7 +18,7 @@ func smtpOwnerResetHex(to string, toName string, resetHex string) error {
var body bytes.Buffer var body bytes.Buffer
templates["reset-hex"].Execute(&body, &ownerResetHexPlugs{Origin: os.Getenv("ORIGIN"), ResetHex: resetHex}) 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 { if err != nil {
logger.Errorf("cannot send reset email: %v", err) logger.Errorf("cannot send reset email: %v", err)
return errorCannotSendEmail return errorCannotSendEmail