mailer

package module
v0.0.0-...-6f48b38 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: MIT Imports: 11 Imported by: 0

README

Wrapper of SDKs(SendGrid, MailGun, Gmail, AWS SES, SSL SMTP) Mailer

Codeship Status for thiagozs/sendmail-poc-go Go Report Card

  • Go 1.9
  • SDK Sendgrid
  • SDK Mailgun
  • SDK Gmail
  • SDK AWS SES
  • Simple SSL SMTP
  • Glide package manager
  • Linux

Just get the package.

go get -v github.com/thiagozs/mailer-go

To run the study just execute the env.sh file to setup the path and exports.

$. ./env.sh

In your {your-project}/src run the glide to download the dependencies of project.

.../src$ glide up

On root of project, create the file .env with the contents:

SENDGRID_API_KEY=...
MAILGUN_DOMAIN=...
MAILGUN_API_KEY=...
MAILGUN_PUB_KEY=...
GMAIL_LOGIN=...
GMAIL_PASSWD=...
EMAILFROM=...
EMAILFROMNAME=...
EMAILTO=...
EMAILTONAME=...
SMTPSSL_USER=...
SMTPSSL_PASSWD=...
SMTPSSL_SERVER=...
SMTPSSL_PORT=...

The project is open for any upgrade / commit, submit your proof of concept (POC).

Simple example of code implementation.

package main

import (
	"fmt"
	mailer "github.com/thiagozs/mailer-go"
	"time"
)

func main() {

	//Sendgrid Instance
	sg := mailer.NewMailerSendGrid(os.Getenv("SENDGRID_API_KEY"))
	sg.Delay = time.Second * 5

	//Mailgun Instance
	mg := mailer.NewMailerMailGun(os.Getenv("MAILGUN_DOMAIN"),
		os.Getenv("MAILGUN_API_KEY"),
		os.Getenv("MAILGUN_PUB_KEY"))
	mg.Delay = time.Second * 5

	//Gmail Instance
	gm := mailer.NewMailerGmail(os.Getenv("GMAIL_LOGIN"),
		os.Getenv("GMAIL_PASSWD"))
	gm.Delay = time.Second * 5

	// --------------

	// Sendgrid configs
	sg.ConfigEmail = mailer.ConfigEmailSendgrid{
		ContentHTML:      "<b>Test</b>",
		ContentPlainText: "Test",
		EmailFromName:    "Thiago Zilli",
		EmailFrom:        "yourmail@host.com",
		EmailToName:      "Client Name here",
		EmailTo:          "emailofclient@host.com",
		Subject:          "Test email",
	}

	// Mailgun configs
	mg.ConfigEmail = mailer.ConfigEmailMailGun{
		ContentPlainText: "Test",
		EmailFrom:        "yourmail@host.com",
		EmailTo:          "emailofclient@host.com",
		Subject:          "Test email",
	}

	// Gmail Configs
	gm.ConfigEmail = mailer.ConfigEmailGmail{
		ContentHTML: "<b>Test with Gmail</b>",
		EmailFrom:   "yourmail@host.com",
		EmailTo:     "emailofclient@host.com",
		Subject:     "Test email",
	}

	// --------------

	// Send email by Sendgrid
	if err := sg.SendMail(); err != nil {
		fmt.Printf("Sendgrid Error: %s\n", err.Error())
	}

	// Send email by Mailgun
	if err := mg.SendMail(); err != nil {
		fmt.Printf("Mailgun Error: %s\n", err.Error())
	}

	// Send email by Gmail
	if err := gm.SendMail(); err != nil {
		fmt.Printf("Mailgun Error: %s\n", err.Error())
	}

}

ToDos

  • Wrapper Sendgrid
  • Wrapper Mailgun
  • Wrapper Gmail
  • Wrapper AWS SES
  • Simple SSL SMTP
  • Tests

Autors

  • Thiago Z S - @thiagozs (Github) / @thiagozs (Twitter)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIsEmptyCfg

func CheckIsEmptyCfg(cfg interface{}) bool

CheckIsEmptyCfg check if config is empty

Types

type ConfigEmailAWSSES

type ConfigEmailAWSSES struct {
	EmailFrom        string
	EmailTo          string
	Subject          string
	ContentPlainText string
	ContentHTML      string
}

ConfigEmailAWSSES configuration of send.

type ConfigEmailGmail

type ConfigEmailGmail struct {
	EmailTo     string
	EmailFrom   string
	ContentHTML string
	Subject     string
}

ConfigEmailGmail configuration of send

type ConfigEmailMailGun

type ConfigEmailMailGun struct {
	EmailTo          string
	EmailFrom        string
	ContentPlainText string
	Subject          string
}

ConfigEmailMailGun configuration of send

type ConfigEmailSMTPSSL

type ConfigEmailSMTPSSL struct {
	EmailFrom        string
	EmailTo          string
	Subject          string
	ContentPlainText string
	ContentHTML      string
}

ConfigEmailSMTPSSL configuration of send.

type ConfigEmailSendgrid

type ConfigEmailSendgrid struct {
	EmailTo          string
	EmailFrom        string
	EmailToName      string
	EmailFromName    string
	ContentHTML      string
	ContentPlainText string
	Subject          string
}

ConfigEmailSendgrid configuration of send

type GmailLogin

type GmailLogin struct {
	User     string
	Password string
}

GmailLogin username and password for gmail

type SDK

type SDK struct {
	Mailgun  mailgun.Mailgun
	Sendgrid *sendgrid.Client
	Gmail    GmailLogin
	AWSSES   *ses.SES
	SMTPSSL  SMTPLoginSSL
}

SDK wrapper of APIs

type SDKConfigAWSSES

type SDKConfigAWSSES struct {
	SecretKey   string
	AccessKey   string
	Region      string
	SDKName     string
	Delay       time.Duration
	ConfigEmail ConfigEmailAWSSES
}

SDKConfigAWSSES cfg SDKs

func NewMailerAWSSES

func NewMailerAWSSES(accesskey string, secretkey string, region string) *SDKConfigAWSSES

NewMailerAWSSES new instance of AWS

func (*SDKConfigAWSSES) SendMail

func (cfg *SDKConfigAWSSES) SendMail() error

SendMail sendemail

type SDKConfigGmail

type SDKConfigGmail struct {
	User        string
	Password    string
	SDKName     string
	Delay       time.Duration
	ConfigEmail ConfigEmailGmail
}

SDKConfigGmail cfg SDKs

func NewMailerGmail

func NewMailerGmail(user string, password string) *SDKConfigGmail

NewMailerGmail new instace for Gmail login

func (*SDKConfigGmail) SendMail

func (cfg *SDKConfigGmail) SendMail() error

SendMail sendemail

type SDKConfigMailGun

type SDKConfigMailGun struct {
	MailGunDomain string
	MailGunAPIKey string
	MailGunPUBKey string
	SDKName       string
	Delay         time.Duration
	ConfigEmail   ConfigEmailMailGun
}

SDKConfigMailGun cfg SDKs

func NewMailerMailGun

func NewMailerMailGun(domain string, apikey string, pubkey string) *SDKConfigMailGun

NewMailerMailGun new instance of MailGun

func (*SDKConfigMailGun) SendMail

func (cfg *SDKConfigMailGun) SendMail() error

SendMail sendemail

type SDKConfigSMTPSSL

type SDKConfigSMTPSSL struct {
	User        string
	Password    string
	Server      string
	Port        string
	SDKName     string
	Delay       time.Duration
	ConfigEmail ConfigEmailSMTPSSL
}

SDKConfigSMTPSSL cfg SDKs

func NewMailerSMTPSSL

func NewMailerSMTPSSL(user string, password string, server string, port string) *SDKConfigSMTPSSL

NewMailerSMTPSSL new instace for SMTP login

func (*SDKConfigSMTPSSL) SendMail

func (cfg *SDKConfigSMTPSSL) SendMail() error

SendMail sendemail

type SDKConfigSengrid

type SDKConfigSengrid struct {
	SendGridAPIKey string
	SDKName        string
	Delay          time.Duration
	ConfigEmail    ConfigEmailSendgrid
}

SDKConfigSengrid cfg SDKs

func NewMailerSendGrid

func NewMailerSendGrid(apikey string) *SDKConfigSengrid

NewMailerSendGrid new instance of SendGrid

func (*SDKConfigSengrid) SendMail

func (cfg *SDKConfigSengrid) SendMail() error

SendMail sendemail

type SMTPLoginSSL

type SMTPLoginSSL struct {
	User     string
	Password string
	Server   string
	Port     string
}

SMTPLoginSSL username and password for gmail

Jump to

Keyboard shortcuts

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