1
0
mirror of https://github.com/nikoksr/notify.git synced 2025-01-24 03:16:35 +02:00

refactor: proper variable naming

This commit is contained in:
Haris Chaniotakis 2021-02-12 19:08:34 +02:00
parent 39fcea62f6
commit 2f93b48042

View File

@ -39,28 +39,28 @@ func (s *SendGrid) AddReceivers(addresses ...string) {
// html as markup language. // html as markup language.
func (s SendGrid) Send(subject, message string) error { func (s SendGrid) Send(subject, message string) error {
from := mail.NewEmail(s.senderName, s.senderAddress) from := mail.NewEmail(s.senderName, s.senderAddress)
c := mail.NewContent("text/html", message) content := mail.NewContent("text/html", message)
// Create a new personalization instance to be able to add multiple receiver addresses. // Create a new personalization instance to be able to add multiple receiver addresses.
p := mail.NewPersonalization() personalization := mail.NewPersonalization()
p.Subject = subject personalization.Subject = subject
for _, receiverAddress := range s.receiverAddresses { for _, receiverAddress := range s.receiverAddresses {
p.AddTos(mail.NewEmail(receiverAddress, receiverAddress)) personalization.AddTos(mail.NewEmail(receiverAddress, receiverAddress))
} }
m := mail.NewV3Mail() mailMessage := mail.NewV3Mail()
m.AddPersonalizations(p) mailMessage.AddPersonalizations(personalization)
m.AddContent(c) mailMessage.AddContent(content)
m.SetFrom(from) mailMessage.SetFrom(from)
resp, err := s.client.Send(m) resp, err := s.client.Send(mailMessage)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to send mail using SendGrid service") return errors.Wrap(err, "failed to send mail using SendGrid service")
} }
if resp.StatusCode != http.StatusAccepted { if resp.StatusCode != http.StatusAccepted {
return errors.New("failed to send mail using SendGrid service") return errors.New("the SendGrid endpoint did not accept the message")
} }
return nil return nil