Skip to content

Commit

Permalink
feat: use gomail for shoutrrr SMTP
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 15, 2023
1 parent 7dd89ba commit 75e2136
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mail/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type Mail struct {
message *gomail.Message
}

func (t *Mail) SetFrom(from string) *Mail {
t.message.SetHeader("From", from)
return t
}

func New(to, subject, body, contentType string) *Mail {
m := gomail.NewMessage()
m.SetHeader("From", FromAddress)
Expand Down
19 changes: 19 additions & 0 deletions notification/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ func Send(ctx *api.Context, connectionName, shoutrrrURL, title, message string,
var params *types.Params
if properties != nil {
params = (*types.Params)(&allProps)
} else {
params = &types.Params{}
}

// NOTE: Until shoutrrr fixes the "UseHTML" props, we'll use the mailer package
if service == "smtp" {
parsedURL, err := url.Parse(shoutrrrURL)
if err != nil {
return fmt.Errorf("failed to parse shoutrrr URL: %w", err)
}

query := parsedURL.Query()
var (
to = utils.Coalesce(query.Get("ToAddresses"), (*params)["ToAddresses"])
from = utils.Coalesce(query.Get("FromAddress"), (*params)["FromAddress"])
)

m := mail.New(to, title, message, `text/html; charset="UTF-8"`).SetFrom(from)
return m.Send()
}

sendErrors := sender.Send(message, params)
Expand Down

0 comments on commit 75e2136

Please sign in to comment.