gomailer

Gomailer provides a simple email interface to integrate third party email services.

MIT License

Stars
14

Package gomailer

This package provides a simple email interface to integrate third party email services. You can integrate popular email services and switch easily.

Installation

Install the package using

$ go get github.com/thedevsaddam/gomailer

Usage

To use the package import it in your *.go code

import "github.com/thedevsaddam/gomailer"

Integration

package main

import (
	"log"

	mailer "github.com/thedevsaddam/gomailer"
)

func main() {
	c := mailer.Configs{
		Domain: "Your domain here",
		APIKey: "Your key here",
	}

	m, err := mailer.New(mailer.MAILGUN, c)
	checkError(err)

	m.From("John Doe", "[email protected]")
	m.To("Jane Doe", "[email protected]")
	m.Cc("Tom", "[email protected]")
	m.Bcc("Jerry", "[email protected]")
  	m.ReplyTo("Salman", "[email protected]")
	m.Subject("mailgun: Urgent email about tom & jerry")
	// m.BodyText("This is a test text email")
	m.BodyHTML("<html>Inline image here: <img src='cid:a.jpg'></html>")
	m.AttachmentFile("a.jpg")

	checkError(err)
	err = m.Send()
	checkError(err)
}

func checkError(err error) {
	if err != nil {
		log.Println(err)
	}
}

You can chain methods easily

m, err := mailer.New(mailer.MAILGUN, c)
m.To("name", "email").Cc("name", "email").Bcc("name", "email").Bcc("name", "email").Subject("Your subject").BodyText("simple message here").AttachmentFile("some/file.zip").Send()

More examples

Roadmap

  • Mailgun
  • Sendgrid
  • Postmark
  • Mailjet
  • CustomerIO
  • Elasticmail
  • Jangomail
  • Leadersend
  • Madmimi
  • Mandrill
  • Postageapp
  • Socketlabs
  • Sparkpost

Note

This package is under development, need to write tests, unimplemented services. Use now at your own risk.

Contribution

Your suggestions will be more than appreciated. Read the contribution guide here

See all contributors

Read API doc to know about Available options and Methods

License

The gomailer is an open-source software licensed under the MIT License.