Skip to content

Commit d25746d

Browse files
Merge branch 'main' of https://github.com/sendgrid/sendgrid-go into main
2 parents f299a6c + 4d0ad81 commit d25746d

21 files changed

+211
-40
lines changed

Diff for: CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
[2020-10-14] Version 3.7.0
5+
--------------------------
6+
**Library - Feature**
7+
- [PR #410](https://github.com/sendgrid/sendgrid-go/pull/410): allow personalization of From name and email for each recipient. Thanks to [@JenniferMah](https://github.com/JenniferMah)!
8+
9+
**Library - Fix**
10+
- [PR #272](https://github.com/sendgrid/sendgrid-go/pull/272): Accept empty html on Email helper NewSingleEmail(). Thanks to [@tjun](https://github.com/tjun)!
11+
12+
413
[2020-09-28] Version 3.6.4
514
--------------------------
615
**Library - Fix**

Diff for: FIRST_TIMERS.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ Before creating a pull request, make sure that you respect the repository's cons
6161
* [Node.js SDK](https://github.com/sendgrid/sendgrid-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
6262
* [Java SDK](https://github.com/sendgrid/sendgrid-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
6363
* [Go SDK](https://github.com/sendgrid/sendgrid-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
64-
* [Python STMPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
65-
* [PHP STMPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
66-
* [C# STMPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
67-
* [Ruby STMPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
68-
* [Node.js STMPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
69-
* [Java STMPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
70-
* [Go STMPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
64+
* [Python SMTPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
65+
* [PHP SMTPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
66+
* [C# SMTPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
67+
* [Ruby SMTPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
68+
* [Node.js SMTPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
69+
* [Java SMTPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
70+
* [Go SMTPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
7171
* [Python HTTP Client](https://github.com/sendgrid/python-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
7272
* [PHP HTTP Client](https://github.com/sendgrid/php-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
7373
* [C# HTTP Client](https://github.com/sendgrid/csharp-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)

Diff for: LICENSE.md renamed to LICENSE

File renamed without changes.

Diff for: Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ install:
55

66
test:
77
./go.coverage.sh
8+
bash -c 'diff -u <(echo -n) <(gofmt -d -s .)'
89

910
test-integ: test
1011

Diff for: PULL_REQUEST_TEMPLATE.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Closes #2
1919
A short description of what this PR does.
2020

2121
### Checklist
22-
- [ ] I acknowledge that all my contributions will be made under the project's license
22+
- [x] I acknowledge that all my contributions will be made under the project's license
2323
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
24-
- [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md) and my PR follows them
24+
- [ ] I have read the [Contribution Guidelines](https://github.com/sendgrid/sendgrid-go/blob/main/CONTRIBUTING.md) and my PR follows them
2525
- [ ] I have titled the PR appropriately
2626
- [ ] I have updated my branch with the main branch
2727
- [ ] I have added tests that prove my fix is effective or that my feature works
28-
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
28+
- [ ] I have added the necessary documentation about the functionality in the appropriate .md file
2929
- [ ] I have added inline documentation to the code I modified
3030

31-
If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository.
31+
If you have questions, please file a [support ticket](https://support.sendgrid.com), or create a GitHub Issue in this repository.

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![BuildStatus](https://travis-ci.com/sendgrid/sendgrid-go.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-go)
44
[![Email Notifications Badge](https://dx.sendgrid.com/badge/go)](https://dx.sendgrid.com/newsletter/go)
55
[![GoDoc](https://godoc.org/github.com/sendgrid/sendgrid-go?status.svg)](https://godoc.org/github.com/sendgrid/sendgrid-go)
6-
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
6+
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
77
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
88
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-go.svg)](https://github.com/sendgrid/sendgrid-go/graphs/contributors)
99
[![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-go/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-go)
@@ -251,4 +251,4 @@ If you need help installing or using the library, please check the [Twilio SendG
251251
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
252252

253253
# License
254-
[The MIT License (MIT)](LICENSE.md)
254+
[The MIT License (MIT)](LICENSE)

Diff for: USAGE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3965,7 +3965,7 @@ if err != nil {
39653965
}
39663966
```
39673967

3968-
## Remove an IP from a domain authenticaiton.
3968+
## Remove an IP from a domain authentication.
39693969

39703970
**This endpoint allows you to remove a domain's IP address from that domain's authentication.**
39713971

Diff for: base_interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// Version is this client library's current version
1414
const (
15-
Version = "3.6.4"
15+
Version = "3.7.0"
1616
rateLimitRetry = 5
1717
rateLimitSleep = 1100
1818
)

Diff for: examples/helpers/mail/example.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func kitchenSink() []byte {
5454
mail.NewEmail("Example User", "[email protected]"),
5555
}
5656
p.AddBCCs(bccs...)
57+
from := mail.NewEmail("Example Sender", "[email protected]")
58+
p.AddFrom(from)
5759
p.Subject = "Hello World from the Personalized SendGrid Go Library"
5860
p.SetHeader("X-Test", "test")
5961
p.SetHeader("X-Mock", "true")
@@ -101,14 +103,14 @@ func kitchenSink() []byte {
101103
a.SetType("application/pdf")
102104
a.SetFilename("balance_001.pdf")
103105
a.SetDisposition("attachment")
104-
a.SetContentID("Balance Sheet")
105106
m.AddAttachment(a)
106107

107108
a2 := mail.NewAttachment()
108109
a2.SetContent("BwdW")
109110
a2.SetType("image/png")
110111
a2.SetFilename("banner.png")
111112
a2.SetDisposition("inline")
113+
// Content-ID header is included when the attachment disposition is set to "inline"
112114
a2.SetContentID("Banner")
113115
m.AddAttachment(a2)
114116

Diff for: examples/mail/mail.go

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func v3MailSend() {
141141
"substitutions": {
142142
"id": "substitutions",
143143
"type": "object"
144+
},
145+
"from": {
146+
"email": "[email protected]",
147+
"name": "Bob Doe"
144148
},
145149
"to": [
146150
{

Diff for: helpers/eventwebhook/eventwebhook_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func generateTestPayload() []byte {
3232
},
3333
})
3434
payload := buffer.Bytes()
35-
payload = payload[:len(payload)-1] // Drop the trailing newline the encoder adds.
35+
payload = payload[:len(payload)-1] // Drop the trailing newline the encoder adds.
3636
payload = append(payload, []byte("\r\n")...) // Append the expected trailing carriage return and newline!
3737
return payload
3838
}

Diff for: helpers/inbound/inbound.go

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
)
1212

13-
1413
type ParsedEmail struct {
1514
Headers map[string]string
1615
Body map[string]string

Diff for: helpers/mail/mail_v3.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type SGMailV3 struct {
3030
// Personalization holds mail body struct
3131
type Personalization struct {
3232
To []*Email `json:"to,omitempty"`
33+
From *Email `json:"from,omitempty"`
3334
CC []*Email `json:"cc,omitempty"`
3435
BCC []*Email `json:"bcc,omitempty"`
3536
Subject string `json:"subject,omitempty"`
@@ -313,6 +314,11 @@ func (p *Personalization) AddTos(to ...*Email) {
313314
p.To = append(p.To, to...)
314315
}
315316

317+
//AddFrom ...
318+
func (p *Personalization) AddFrom(from *Email) {
319+
p.From = from
320+
}
321+
316322
// AddCCs ...
317323
func (p *Personalization) AddCCs(cc ...*Email) {
318324
p.CC = append(p.CC, cc...)
@@ -613,9 +619,14 @@ func NewEmail(name string, address string) *Email {
613619

614620
// NewSingleEmail ...
615621
func NewSingleEmail(from *Email, subject string, to *Email, plainTextContent string, htmlContent string) *SGMailV3 {
616-
plainText := NewContent("text/plain", plainTextContent)
617-
html := NewContent("text/html", htmlContent)
618-
return NewV3MailInit(from, subject, to, plainText, html)
622+
var contents []*Content
623+
if plainTextContent != "" {
624+
contents = append(contents, NewContent("text/plain", plainTextContent))
625+
}
626+
if htmlContent != "" {
627+
contents = append(contents, NewContent("text/html", htmlContent))
628+
}
629+
return NewV3MailInit(from, subject, to, contents...)
619630
}
620631

621632
// NewContent ...

Diff for: helpers/mail/mail_v3_test.go

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mail
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"math/rand"
67
"testing"
@@ -257,6 +258,18 @@ func TestV3PersonalizationAddTos(t *testing.T) {
257258
assert.Equal(t, len(tos), len(p.To), fmt.Sprintf("length of To should be %d, got %d", len(tos), len(p.To)))
258259
}
259260

261+
func TestV3PersonalizationAddFrom(t *testing.T) {
262+
address := "[email protected]"
263+
name := "Test User"
264+
from := NewEmail(name, address)
265+
266+
p := NewPersonalization()
267+
p.AddFrom(from)
268+
269+
assert.Equal(t, name, p.From.Name, fmt.Sprintf("name should be %s got %s", name, p.From.Name))
270+
assert.Equal(t, address, p.From.Address, fmt.Sprintf("address should be %s got %s", address, p.From.Address))
271+
}
272+
260273
func TestV3PersonalizationAddCCs(t *testing.T) {
261274
ccs := []*Email{
262275
NewEmail("Example User", "[email protected]"),
@@ -680,10 +693,32 @@ func TestV3NewSingleEmailWithEmptyHTMLContent(t *testing.T) {
680693

681694
message := NewSingleEmail(from, subject, to, plainTextContent, "")
682695

683-
assert.NotNil(t, message, "NewV3MailInit() shouldn't return nil")
684-
assert.NotNil(t, message.From, "From shouldn't be nil")
685-
assert.Equal(t, message.Subject, subject, fmt.Sprintf("Subject should be %s, got %s", subject, message.Subject))
686-
assert.NotNil(t, message.Content, "Content shouldn't be nil")
696+
m, _ := json.Marshal(message)
697+
fmt.Println(string(m))
698+
699+
if message == nil {
700+
t.Errorf("NewV3MailInit() shouldn't return nil")
701+
}
702+
703+
if message.From == nil {
704+
t.Errorf("From shouldn't be nil")
705+
}
706+
707+
if message.Subject != subject {
708+
t.Errorf("Subject should be %s, got %s", subject, message.Subject)
709+
}
710+
711+
if message.Content == nil {
712+
t.Errorf("Content shouldn't be nil")
713+
}
714+
715+
if len(message.Content) != 1 {
716+
t.Errorf("Content length should be 1, got %d", len(message.Content))
717+
}
718+
719+
if len(message.Content) == 1 && message.Content[0].Type != "text/plain" {
720+
t.Errorf("Content type should be 'text/plain', got %s", message.Content[0].Type)
721+
}
687722
}
688723

689724
func TestV3NewClickTrackingSetting(t *testing.T) {

Diff for: sendgrid_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
)
1919

2020
func TestLicenseYear(t *testing.T) {
21-
d, err := ioutil.ReadFile("LICENSE.md")
22-
assert.Nil(t, err, "Cannot read the LICENSE.md file")
21+
d, err := ioutil.ReadFile("LICENSE")
22+
assert.Nil(t, err, "Cannot read the LICENSE file")
2323
l := fmt.Sprintf("Copyright (C) %v, Twilio SendGrid, Inc.", time.Now().Year())
2424
assert.True(t, strings.Contains(string(d), l), fmt.Sprintf("License date range is not correct, it should be: %v", l))
2525
}
@@ -35,7 +35,7 @@ func TestRepoFiles(t *testing.T) {
3535
"CODE_OF_CONDUCT.md",
3636
"CONTRIBUTING.md",
3737
"ISSUE_TEMPLATE.md",
38-
"LICENSE.md",
38+
"LICENSE",
3939
"PULL_REQUEST_TEMPLATE.md",
4040
"README.md",
4141
"TROUBLESHOOTING.md",

Diff for: use-cases/attachments-with-mailer-helper.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func main() {
4343
a_txt.SetType("text/plain")
4444
a_txt.SetFilename("testing.txt")
4545
a_txt.SetDisposition("attachment")
46-
a_txt.SetContentID("Test Document")
4746

4847
// read/attach .pdf file
4948
a_pdf := mail.NewAttachment()
@@ -56,9 +55,8 @@ func main() {
5655
a_pdf.SetType("application/pdf")
5756
a_pdf.SetFilename("testing.pdf")
5857
a_pdf.SetDisposition("attachment")
59-
a_pdf.SetContentID("Test Attachment")
6058

61-
// read/attach .jpg file
59+
// read/attach inline .jpg file
6260
a_jpg := mail.NewAttachment()
6361
dat, err = ioutil.ReadFile("testing.jpg")
6462
if err != nil {
@@ -68,7 +66,7 @@ func main() {
6866
a_jpg.SetContent(encoded)
6967
a_jpg.SetType("image/jpeg")
7068
a_jpg.SetFilename("testing.jpg")
71-
a_jpg.SetDisposition("attachment")
69+
a_jpg.SetDisposition("inline")
7270
a_jpg.SetContentID("Test Attachment")
7371

7472
// add `a_txt`, `a_pdf` and `a_jpg` to `m`
@@ -88,4 +86,4 @@ func main() {
8886
fmt.Println(response.Headers)
8987
}
9088
}
91-
```
89+
```

Diff for: use-cases/attachments-without-mailer-helper.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ func main() {
3838
"attachments": [
3939
{
4040
"content": "SGVsbG8gV29ybGQh",
41-
"content_id": "testing_1",
4241
"disposition": "attachment",
4342
"filename": "testing.txt",
4443
"type": "txt"
4544
},
4645
{
4746
"content": "BASE64 encoded content block here",
47+
"disposition": "inline",
4848
"content_id": "testing_2",
49-
"disposition": "attachment",
5049
"filename": "testing.jpg",
5150
"type": "jpg"
5251
},
5352
{
54-
"content": "BASE64 encoded content block here",
55-
"content_id": "testing_3",
53+
"content": "BASE64 encoded content block here",
5654
"disposition": "attachment",
5755
"filename": "testing.pdf",
5856
"type": "pdf"
@@ -68,4 +66,4 @@ func main() {
6866
fmt.Println(response.Headers)
6967
}
7068
}
71-
```
69+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
### Personalization (with helper) - Sending Two Different Emails to Two Different Groups of Recipients from two different From emails
3+
4+
```go
5+
package main
6+
7+
import (
8+
"fmt"
9+
"log"
10+
"os"
11+
12+
"github.com/sendgrid/sendgrid-go"
13+
"github.com/sendgrid/sendgrid-go/helpers/mail"
14+
)
15+
16+
func main() {
17+
// create new *SGMailV3
18+
m := mail.NewV3Mail()
19+
20+
from := mail.NewEmail("Example Sender 1", "[email protected]")
21+
content := mail.NewContent("text/html", "<p>Personalizations are awesome!</p>")
22+
23+
m.SetFrom(from)
24+
m.AddContent(content)
25+
26+
// create new *Personalization(s)
27+
personalization1 := mail.NewPersonalization()
28+
personalization2 := mail.NewPersonalization()
29+
30+
// populate `personalization1` with data
31+
//this email will be sent from Example Sender 1
32+
p1_to := mail.NewEmail("Example User 1", "[email protected]")
33+
34+
personalization1.AddTos(p1_to)
35+
personalization1.Subject = "Having fun learning about personalizations?"
36+
37+
// populate `personalization2` with data
38+
//this email will be sent from Example Sender 2
39+
p2_from :=mail.NewEmail("Example Sender 2", "[email protected]")
40+
p2_to := mail.NewEmail("Example User 1", "[email protected]")
41+
42+
personalization2.AddFrom(p2_from)
43+
personalization2.AddTos(p2_to)
44+
personalization2.Subject = "Personalizations are fun!"
45+
46+
// add `personalization1` and `personalization2` to `m`
47+
m.AddPersonalizations(personalization1, personalization2)
48+
49+
request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
50+
request.Method = "POST"
51+
request.Body = mail.GetRequestBody(m)
52+
response, err := sendgrid.API(request)
53+
if err != nil {
54+
log.Println(err)
55+
} else {
56+
fmt.Println(response.StatusCode)
57+
fmt.Println(response.Body)
58+
fmt.Println(response.Headers)
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)