gomailer

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 19 Imported by: 0

README

Package gomailer

Go Report Card GoDoc License

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", "john@example.com")
	m.To("Jane Doe", "jane@example.com")
	m.Cc("Tom", "tom@example.com")
	m.Bcc("Jerry", "jerry@example.com")
  	m.ReplyTo("Salman", "joye@example.com")
	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.

Documentation

Overview

Package gomailer provides a simple email interface to integrate third party email services

Index

Constants

View Source
const (

	// MAILGUN driver
	MAILGUN driver
	// SENDGRID driver
	SENDGRID
	// POSTMARK driver
	POSTMARK
	// MAILJET driver
	MAILJET
	// CUSTOMERIO driver
	CUSTOMERIO
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Configs

type Configs struct {
	ServerToken    string        // ServerToken for service like postmarkapp
	AccountToken   string        // AccountToken for service like postmarkapp
	APIKey         string        // APIKey represents the API key for mail service like mailgun
	PrivateKey     string        // PrivateKey represents  the PrivateKey provided by service like mailjet
	PublicKey      string        // PublicKey represents  the PublicKey provided by service like mailjet
	BaseURL        string        // BaseURL represents the base url for service
	Domain         string        // Domain represents the domain of the service
	Username       string        // Username represents the username for service
	Password       string        // Password represents the password for service
	RequestTimeout time.Duration // RequestTimeout represents the timeout for http client call
}

Configs represents the configurations

type Mailer

type Mailer interface {
	// From set sender email address for an email
	From(name, from string) Mailer
	// From set receipents email address for an email
	To(name, to string) Mailer
	// From set Cc receipents email address for an email
	Cc(name, to string) Mailer
	// From set Bcc receipents email address for an email
	Bcc(name, to string) Mailer
	// ReplyTo sets reply-to for an email
	ReplyTo(name, email string) Mailer
	// Subject sents Subject of an email
	Subject(sub string) Mailer
	// BodyHTML sets html body for an email
	BodyHTML(html string) Mailer
	// BodyText sets plain text body for an email
	BodyText(text string) Mailer
	// AttachmentFile sets email attachments from file name on disk
	AttachmentFile(file string) Mailer
	// AttachmentInlineFile sets email inline attachments from file name on disk
	AttachmentInlineFile(file string) Mailer
	// AttachmentReader sets email attachments from file name and reader
	AttachmentReader(file string, r io.Reader) Mailer
	// AttachmentInlineFile sets email inline attachments from file name and reader
	AttachmentInlineReader(file string, r io.Reader) Mailer
	// Send process an email sending
	Send() error
}

Mailer describes a common mailer interface for different email service

func New

func New(d driver, c Configs) (Mailer, error)

New Return a new mail driver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL