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: support email SendHtml #30

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/services/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The Email notification service sends email notifications using SMTP protocol and
* `username` - username
* `password` - password
* `from` - from email address
* `html` - optional bool, true or false

## Example

Expand Down
11 changes: 9 additions & 2 deletions pkg/services/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type EmailOptions struct {
Username string `json:"username"`
Password string `json:"password"`
From string `json:"from"`
Html bool `json:"html"`
}

type emailService struct {
Expand All @@ -73,12 +74,18 @@ func (s *emailService) Send(notification Notification, dest Destination) error {
subject = notification.Email.Subject
body = text.Coalesce(notification.Email.Body, body)
}
return smtp.New(smtp.Options{
email := smtp.New(smtp.Options{
From: s.opts.From,
Host: s.opts.Host,
Port: s.opts.Port,
InsecureSkipVerify: s.opts.InsecureSkipVerify,
Password: s.opts.Password,
Username: s.opts.Username,
}).WithSubject(subject).WithBody(body).To(dest.Recipient).Send()
}).WithSubject(subject).WithBody(body).To(dest.Recipient)

if s.opts.Html {
return email.SendHtml()
} else {
return email.Send()
}
}