Skip to content
forked from keighl/mandrill

Simple package for sending emails through the Mandrill API.

License

Notifications You must be signed in to change notification settings

smallpdf/mandrill

 
 

Repository files navigation

Mandrill Emails via Golang

Build Status Coverage Status

Stripped down package for sending emails through the Mandrill API. Inspired by @mostafah's implementation.

Installation

go get -u github.com/keighl/mandrill

Upgrading to 1.0

MessagesSend() and MessagesSendTemplate() now only returns 1 error interface (as opposed to a non-sensical 2).

// New!
res, err := client.MessagesSend(m)

// Old!
res, apiError, err := client.MessagesSend(m)

Documentation

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

Regular Message

https://mandrillapp.com/api/docs/messages.JSON.html#method=send

import (
    m "github.com/keighl/mandrill"
)

client := m.ClientWithKey("XXXXXXXXX")

message := &m.Message{}
message.AddRecipient("[email protected]", "Bob Johnson", "to")
message.FromEmail = "[email protected]"
message.FromName = "Kyle Truscott"
message.Subject = "You won the prize!"
message.HTML = "<h1>You won!!</h1>"
message.Text = "You won!!"

responses, err := client.MessagesSend(message)

Send Template

https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template

http://help.mandrill.com/entries/21694286-How-do-I-add-dynamic-content-using-editable-regions-in-my-template-

templateContent := map[string]string{"header": "Bob! You won the prize!"}
responses, err := client.MessagesSendTemplate(message, "you-won", templateContent)

Including Merge Tags

http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content-

// Global vars
message.GlobalMergeVars = m.MapToVars(map[string]interface{}{"name": "Bob"})

// Recipient vars
bobVars := m.MapToRecipientVars("[email protected]", map[string]interface{}{"name": "Bob"})
jillVars := m.MapToRecipientVars("[email protected]", map[string]interface{}{"name": "Jill"})
message.MergeVars = []*m.RcptMergeVars{bobVars, jillVars}

Integration Testing Keys

You can pass special API keys to the client to mock success/err responses from MessagesSend or MessagesSendTemplate.

// Sending messages will be successful, but without a real API request
c := ClientWithKey("SANDBOX_SUCCESS")

// Sending messages will error, but without a real API request
c := ClientWithKey("SANDBOX_ERROR")

About

Simple package for sending emails through the Mandrill API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.8%
  • Makefile 0.2%