Skip to content

Commit

Permalink
feat: support email SendHtml (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryota Sakamoto <sakamo.ryota+github@gmail.com>
  • Loading branch information
ryota-sakamoto authored May 27, 2021
1 parent e8e2938 commit 6e7a433
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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()
}
}

0 comments on commit 6e7a433

Please sign in to comment.