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

SendGrid: Updating to the newest version of SendGrid #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 13 additions & 19 deletions auth/sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,24 @@ func (e *EMail) SendWithoutUnsubscribeHeader(ctx context.Context) error {
if e.FromAddr == "" || e.ToAddr == "" || e.Subject == "" || (e.TextBody == "" && e.HTMLBody == "") {
return fmt.Errorf("invalid EMail %+v", e)
}
if(e.FromName == nil){
e.FromName = ""
}
if(e.ToName == nil) {
e.ToName = ""
}

from := mail.NewEmail(e.FromName, e.FromAddr)
subject := e.Subject
to := mail.NewEmail(e.ToName, e.ToAddr)
plainTextContent := e.TextBody
htmlContent := e.HTMLBody
msg := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)

sendGridConf, err := GetSendGrid(ctx)
if err != nil {
return err
}

msg := mail.NewV3Mail()
if e.TextBody != "" {
msg.AddContent(mail.NewContent(
"text/plain",
e.TextBody,
))
}
if e.HTMLBody != "" {
msg.AddContent(mail.NewContent(
"text/html",
e.HTMLBody,
))
}
msg.Subject = e.Subject
p := mail.NewPersonalization()
p.AddTos(mail.NewEmail(e.ToName, e.ToAddr))
msg.AddPersonalizations(p)
msg.SetFrom(mail.NewEmail(e.FromName, e.FromAddr))
if e.UnsubscribeURL != "" {
msg.SetHeader("List-Unsubscribe", fmt.Sprintf("<%s>", e.UnsubscribeURL))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/mafredri/go-trueskill v0.0.0-20190101120706-fc89fbba5a88
github.com/oddg/hungarian-algorithm v0.0.0-20170809162819-9567cbc363de
github.com/sendgrid/rest v2.4.1+incompatible
github.com/sendgrid/sendgrid-go v3.5.0+incompatible
github.com/sendgrid/sendgrid-go v3.14.0+incompatible
github.com/zond/enmime v0.6.1
github.com/zond/go-fcm v0.1.0
github.com/zond/goaeoas v0.1.10
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ github.com/sendgrid/rest v2.4.1+incompatible h1:HDib/5xzQREPq34lN3YMhQtMkdXxS/qL
github.com/sendgrid/rest v2.4.1+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/sendgrid/sendgrid-go v3.5.0+incompatible h1:kosbgHyNVYVaqECDYvFVLVD9nvThweBd6xp7vaCT3GI=
github.com/sendgrid/sendgrid-go v3.5.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/sendgrid/sendgrid-go v3.14.0+incompatible h1:KDSasSTktAqMJCYClHVE94Fcif2i7P7wzISv1sU6DUA=
github.com/sendgrid/sendgrid-go v3.14.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down