Skip to content

Commit 4bfd4e6

Browse files
committed
fix SetRecipients clear empty strings
1 parent fb0c4b6 commit 4bfd4e6

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ type Attachment struct {
5454
type Message struct {
5555
Subject string `json:"subject"`
5656
Body Body `json:"body"`
57-
ToRecipients []Recipient `json:"toRecipients"`
58-
CcRecipients []Recipient `json:"ccRecipients"`
59-
BccRecipients []Recipient `json:"bccRecipients"`
57+
ToRecipients []Recipient `json:"toRecipients,omitempty"`
58+
CcRecipients []Recipient `json:"ccRecipients,omitempty"`
59+
BccRecipients []Recipient `json:"bccRecipients,omitempty"`
6060
Attachments []Attachment `json:"attachments,omitempty"`
6161
}
6262

send_email.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ func (c *Client) SendEmail(subject, body string, contentType ContentType, saveSe
4545
}
4646

4747
func SetRecipients(recipients []string) []Recipient {
48-
result := make([]Recipient, len(recipients))
49-
for i, recipient := range recipients {
50-
result[i] = Recipient{
51-
EmailAddress: EmailAddress{
52-
Address: recipient,
53-
},
48+
result := make([]Recipient, 0)
49+
for _, recipient := range recipients {
50+
if recipient != "" {
51+
result = append(result, Recipient{
52+
EmailAddress: EmailAddress{
53+
Address: recipient,
54+
}})
5455
}
5556
}
5657
return result

0 commit comments

Comments
 (0)