Skip to content

Commit

Permalink
generalise smtp config (#3059)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 authored Aug 22, 2024
1 parent a5bff96 commit 14bdb4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pro/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ const (
func init() {
switch EmailSenderType(servercfg.EmailSenderType()) {
case Smtp:
client = &SmtpSender{
smtpSender := &SmtpSender{
SmtpHost: servercfg.GetSmtpHost(),
SmtpPort: servercfg.GetSmtpPort(),
SenderEmail: servercfg.GetSenderEmail(),
SendUser: servercfg.GetSenderUser(),
SenderPass: servercfg.GetEmaiSenderAuth(),
}
if smtpSender.SendUser == "" {
smtpSender.SendUser = smtpSender.SenderEmail
}
client = smtpSender

case Resend:
client = NewResendEmailSenderFromConfig()
}
Expand Down
3 changes: 2 additions & 1 deletion pro/email/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type SmtpSender struct {
SmtpHost string
SmtpPort int
SenderEmail string
SendUser string
SenderPass string
}

Expand All @@ -27,7 +28,7 @@ func (s *SmtpSender) SendEmail(ctx context.Context, n Notification, e Mail) erro
// Set E-Mail body. You can set plain text or html with text/html
m.SetBody("text/html", e.GetBody(n))
// Settings for SMTP server
d := gomail.NewDialer(s.SmtpHost, s.SmtpPort, s.SenderEmail, s.SenderPass)
d := gomail.NewDialer(s.SmtpHost, s.SmtpPort, s.SendUser, s.SenderPass)

// This is only needed when SSL/TLS certificate is not valid on server.
// In production this should be set to false.
Expand Down
12 changes: 11 additions & 1 deletion servercfg/serverconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,19 @@ func GetSenderEmail() string {
return v
}

func GetSenderUser() string {
v := ""
if fromEnv := os.Getenv("EMAIL_SENDER_USER"); fromEnv != "" {
v = fromEnv
} else if fromCfg := config.Config.Server.EmailSenderAddr; fromCfg != "" {
v = fromCfg
}
return v
}

func GetEmaiSenderAuth() string {
v := ""
if fromEnv := os.Getenv("EMAIL_SENDER_AUTH"); fromEnv != "" {
if fromEnv := os.Getenv("EMAIL_SENDER_PASSWORD"); fromEnv != "" {
v = fromEnv
} else if fromCfg := config.Config.Server.EmailSenderAddr; fromCfg != "" {
v = fromCfg
Expand Down

0 comments on commit 14bdb4f

Please sign in to comment.