Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.out
.idea/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Stripped down package for sending emails through the Mandrill API. Inspired by [

### Installation

go get -u github.com/keighl/mandrill
go get -u github.com/maytechnet/mandrill

### Upgrading to 1.0

Expand All @@ -22,7 +22,7 @@ res, apiError, err := client.MessagesSend(m)

### Documentation

http://godoc.org/github.com/keighl/mandrill
https://godoc.org/github.com/maytechnet/mandrill

### Regular Message

Expand Down
77 changes: 76 additions & 1 deletion mandrill.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,48 @@ type Message struct {
SendAt string `json:"-"`
}

// MessageInfo represents payload sent to the API
type MessageInfo struct {
// the message's unique id
Id string `json:"_id"`
}

// ResponseMsgInfo holds details of the message info
type ResponseMsgInfo struct {
Ts int `json:"ts"`
ID string `json:"_id"`
Sender string `json:"sender"`
Template string `json:"template"`
Subject string `json:"subject"`
Email string `json:"email"`
Tags []string `json:"tags"`
Opens int `json:"opens"`
OpensDetail []struct {
Ts int `json:"ts"`
IP string `json:"ip"`
Location string `json:"location"`
Ua string `json:"ua"`
} `json:"opens_detail"`
Clicks int `json:"clicks"`
ClicksDetail []struct {
Ts int `json:"ts"`
URL string `json:"url"`
IP string `json:"ip"`
Location string `json:"location"`
Ua string `json:"ua"`
} `json:"clicks_detail"`
State string `json:"state"`
Metadata struct {
UserID string `json:"user_id"`
Website string `json:"website"`
} `json:"metadata"`
SMTPEvents []struct {
Ts int `json:"ts"`
Type string `json:"type"`
Diag string `json:"diag"`
} `json:"smtp_events"`
}

// To is a single recipient's information.
type To struct {
// the email address of the recipient
Expand Down Expand Up @@ -209,13 +251,15 @@ func (err Error) Error() string {
return err.Message
}

const BaseURL = "https://mandrillapp.com/api/1.0/"

// ClientWithKey returns a mandrill.Client pointer armed with the supplied Mandrill API key
// For integration testing, you can supply `SANDBOX_SUCCESS` or `SANDBOX_ERROR` as the API key.
func ClientWithKey(key string) *Client {
return &Client{
Key: key,
HTTPClient: &http.Client{},
BaseURL: "https://mandrillapp.com/api/1.0/",
BaseURL: BaseURL,
}
}

Expand Down Expand Up @@ -258,6 +302,37 @@ func (c *Client) MessagesSend(message *Message) (responses []*Response, err erro
return c.sendMessagePayload(data, "messages/send.json")
}

// MessageInfo sends a message via an API client
func (c *Client) MessageInfo(info *MessageInfo) (responses *ResponseMsgInfo, err error) {
if c.Key == "SANDBOX_SUCCESS" {
return responses, nil
}

if c.Key == "SANDBOX_ERROR" {
return nil, errors.New("SANDBOX_ERROR")
}

if info.Id == "" {
return nil, errors.New("email ID empty")
}

var data struct {
Key string `json:"key"`
Id string `json:"id"`
}

data.Key = c.Key
data.Id = info.Id

body, err := c.sendApiRequest(data, "messages/info.json")
if err != nil {
return responses, err
}
responses = new(ResponseMsgInfo)
err = json.Unmarshal(body, &responses)
return responses, err
}

// MessagesSendTemplate sends a message using a Mandrill template
func (c *Client) MessagesSendTemplate(message *Message, templateName string, contents interface{}) (responses []*Response, err error) {

Expand Down