Skip to content

Golang based client API for Mailchimp, including Mandrill

License

Notifications You must be signed in to change notification settings

GoIncremental/gochimp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gochimp

Go based API for Mailchimp, starting with Mandrill.

https://godoc.org/github.com/mattbaird/gochimp

to run tests, set a couple env variables:

$ export MANDRILL_KEY=111111111-1111-1111-1111-111111111
$ export [email protected]

Mandrill Status

  • API Feature complete on Oct 26/2012
  • Adding tests, making naming conventions consistent, and refactoring error handling

Chimp Status

  • Not started

Getting Started

Below is an example approach to rendering custom content into a Mandrill template called "welcome email" and sending the rendered email.

package main

import (
	"fmt"
	"github.com/mattbaird/gochimp"
	"os"
)

func main() {
	apiKey := os.Getenv("MANDRILL_KEY")
	mandrillApi, err := gochimp.NewMandrill(apiKey)

	if err != nil {
		fmt.Println("Error instantiating client")
	}

	templateName := "welcome email"
	contentVar := gochimp.Var{"main", "<h1>Welcome aboard!</h1>"}
	content := []gochimp.Var{contentVar}

	renderedTemplate, err := mandrillApi.TemplateRender(templateName, content, nil)

	if err != nil {
		fmt.Println("Error rendering template")
	}

	recipients := []gochimp.Recipient{
		gochimp.Recipient{Email: "[email protected]"},
	}

	message := gochimp.Message{
		Html:      renderedTemplate,
		Subject:   "Welcome aboard!",
		FromEmail: "[email protected]",
		FromName:  "Boss Man",
		To:        recipients,
	}

	_, err = mandrillApi.MessageSend(message, false)

	if err != nil {
		fmt.Println("Error sending message")
	}
}

About

Golang based client API for Mailchimp, including Mandrill

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 85.5%
  • HTML 14.5%