From e1ded02615ee9f8ef5c62da7c1d1f165cfb0b804 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 2 Sep 2020 12:37:00 +0200 Subject: [PATCH] Fix default-addr and test-email sending --- pkg/mail/mail.go | 4 ++-- system/commands/auth.go | 3 +++ system/service/auth_notification.go | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/mail/mail.go b/pkg/mail/mail.go index f04add437..910589433 100644 --- a/pkg/mail/mail.go +++ b/pkg/mail/mail.go @@ -49,9 +49,9 @@ func SetupDialer(host string, port int, user, pass, from string) { defaultDialerError = errors.New("No port provided for SMTP") return } + if from == "" { - defaultDialerError = errors.New("Sender for SMTP is not set") - return + from = "placeholder@example.net" } if defaultDialerError != nil { diff --git a/system/commands/auth.go b/system/commands/auth.go index eac2ca9ec..10ebc4571 100644 --- a/system/commands/auth.go +++ b/system/commands/auth.go @@ -121,6 +121,9 @@ func Auth() *cobra.Command { ntf = service.DefaultAuthNotification.With(ctx) ) + // Update current settings to be sure that we do not have outdated values + cli.HandleError(service.DefaultSettings.UpdateCurrent(ctx)) + err = ntf.EmailConfirmation("en", args[0], "notification-testing-token") cli.HandleError(err) diff --git a/system/service/auth_notification.go b/system/service/auth_notification.go index de56dc170..05f610ec8 100644 --- a/system/service/auth_notification.go +++ b/system/service/auth_notification.go @@ -75,8 +75,16 @@ func (svc authNotification) PasswordReset(lang string, emailAddress string, toke } func (svc authNotification) newMail() *gomail.Message { - m := gomail.NewMessage() - m.SetAddressHeader("From", svc.settings.Auth.Mail.FromAddress, svc.settings.Auth.Mail.FromName) + var ( + m = mail.New() + addr = svc.settings.Auth.Mail.FromAddress + name = svc.settings.Auth.Mail.FromName + ) + + if addr != "" { + m.SetAddressHeader("From", addr, name) + } + return m }