Coder Social home page Coder Social logo

mandrill's Introduction

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")

mandrill's People

Contributors

bstein-clever avatar c2h5oh avatar cmiller01 avatar frncmx avatar keighl avatar kenegozi avatar ralstan-vaz-bms avatar sayan- avatar tiwillia avatar tylerb avatar

Watchers

 avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.