Skip to content

Commit

Permalink
Add useragent and set version to 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiezane committed Jul 17, 2014
1 parent 15fee02 commit 45937ab
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"net"
"net/http"
"net/url"
"strings"
"time"
)

const Version = "0.5.1"

func timeoutHandler(network, address string) (net.Conn, error) {
return net.DialTimeout(network, address, time.Duration(5*time.Second))
}
Expand Down Expand Up @@ -87,18 +90,24 @@ func (sg *SGClient) Send(m *SGMail) error {
if e != nil {
return e
}
r, e := sg.Client.PostForm(sg.APIMail, values)
req, e := http.NewRequest("POST", sg.APIMail, strings.NewReader(values.Encode()))
if e != nil {
return e
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "sendgrid-go/"+Version+";go")
res, e := sg.Client.Do(req)
if e != nil {
return fmt.Errorf("sendgrid.go: error:%v; response:%v", e, r)
return fmt.Errorf("sendgrid.go: error:%v; response:%v", e, res)
}
defer r.Body.Close()
if r.StatusCode == http.StatusOK {

defer res.Body.Close()

if res.StatusCode == http.StatusOK {
return nil
}
body, _ := ioutil.ReadAll(r.Body)
return fmt.Errorf("sendgrid.go: code:%d error:%v body:%s", r.StatusCode, e, body)

body, _ := ioutil.ReadAll(res.Body)

return fmt.Errorf("sendgrid.go: code:%d error:%v body:%s", res.StatusCode, e, body)
}

0 comments on commit 45937ab

Please sign in to comment.