Files

29 lines
838 B
Go

package email
// Adapted from Sendico's SendGrid notifier (see PROVENANCE.md). The SDK mail
// construction is retained; templates, retries and logging belong to our service.
import (
"context"
"git.sendico.io/tech/sxchnge/notifications/model"
"github.com/sendgrid/sendgrid-go/helpers/mail"
)
type sendgrid struct{ client }
func (s *sendgrid) Send(ctx context.Context, _ string, email model.Email) Outcome {
m := mail.NewV3Mail()
m.SetFrom(mail.NewEmail(s.settings.SenderName, s.settings.SenderAddress))
m.Subject = email.Subject
p := mail.NewPersonalization()
p.AddTos(mail.NewEmail("", email.Address))
m.AddPersonalizations(p)
if email.Text != "" {
m.AddContent(mail.NewContent("text/plain", email.Text))
}
if email.HTML != "" {
m.AddContent(mail.NewContent("text/html", email.HTML))
}
return s.post(ctx, "", m)
}