Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use gomail for shoutrrr SMTP #556

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now this doesn't work for smtp://system ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. At this point in code, the url is never smtp://system. It's already prepopulated. https://github.com/flanksource/incident-commander/blob/cf47ca1327b40638ce8e569691c270d3d6364723/notification/shoutrrr.go#L54-L60

parsedURL, err := url.Parse(shoutrrrURL)
adityathebe marked this conversation as resolved.
Show resolved Hide resolved
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