Skip to content

Commit

Permalink
Change behavior of AddTo and update version
Browse files Browse the repository at this point in the history
  • Loading branch information
elbuo8 committed Nov 5, 2014
1 parent 62169e4 commit de8086f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
[![Build Status](https://travis-ci.org/sendgrid/sendgrid-go.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-go)
SendGrid Helper Library to send emails very easily using Go.

### Warning

Version ``1.1.x``, behaves differently in the ``AddTo`` method. In the past this method defaulted to using the ``SMTPAPI`` header. Now you must explicitly call the ``SMTPAPIHeader.AddTo`` method. More on the ``SMTPAPI`` section.

## Installation

```bash
Expand Down Expand Up @@ -101,12 +105,12 @@ If you wish to use the X-SMTPAPI on your own app, you can use the [SMTPAPI Go li
### Recipients

```go
message.AddTo("addTo@mailinator.com")
message.SMTPAPIHeader.AddTo("addTo@mailinator.com")
// or
tos := []string{"test@test.com", "test@email.com"}
message.AddTos(tos)
message.SMTPAPIHeader.AddTos(tos)
// or
message.SetTos(tos)
message.SMTPAPIHeader.SetTos(tos)
```

### [Substitutions](http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html)
Expand Down
4 changes: 2 additions & 2 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package sendgrid

import (
"encoding/json"
"github.com/sendgrid/smtpapi-go"
"io"
"io/ioutil"
"net/mail"
"time"

"github.com/sendgrid/smtpapi-go"
)

// SGMail is representation of a valid SendGrid Mail
Expand Down Expand Up @@ -55,7 +56,6 @@ func (m *SGMail) AddTos(emails []string) error {

// AddRecipient will add mail.Address emails to recipients.
func (m *SGMail) AddRecipient(recipient *mail.Address) {
m.SMTPAPIHeader.AddTo(recipient.String())
m.To = append(m.To, recipient.Address)
if recipient.Name != "" {
m.ToName = append(m.ToName, recipient.Name)
Expand Down
12 changes: 8 additions & 4 deletions mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func TestAddTo(t *testing.T) {
t.Errorf("AddTo should append to SGMail.To")
case len(m.ToName) != 1:
t.Errorf("AddTo should append to SGMail.ToName on a valid email")
case len(m.SMTPAPIHeader.To) != 1:
t.Errorf("AddTo should also modify the SMTPAPIHeader.To")
}
}

Expand Down Expand Up @@ -65,8 +63,6 @@ func TestAddRecipients(t *testing.T) {
t.Errorf("AddRecipients should append to SGMail.To")
case len(m.ToName) != 2:
t.Errorf("AddRecipients should append to SGMail.ToName if a valid email is supplied")
case len(m.SMTPAPIHeader.To) != 2:
t.Errorf("AddRecipients should append to SMTPAPIHeader.To")
}
}

Expand Down Expand Up @@ -321,3 +317,11 @@ func TestHeaderString(t *testing.T) {
t.Errorf("Error parsing headers: %v", err)
}
}

func TestAddToSMTPAPI(t *testing.T) {
m := NewMail()
m.SMTPAPIHeader.AddTo("example@email.com")
if len(m.SMTPAPIHeader.To) != 1 {
t.Error("SMTPAPIHeader To should be len of 1")
}
}
2 changes: 1 addition & 1 deletion sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

const Version = "1.0.0"
const Version = "1.1.0"

func timeoutHandler(network, address string) (net.Conn, error) {
return net.DialTimeout(network, address, time.Duration(5*time.Second))
Expand Down

0 comments on commit de8086f

Please sign in to comment.