GoMail

donation link

Simplifies Sending Emails In Go.

Installation

  go get github.com/AspieSoft/gomail

Usage

import (
  "github.com/AspieSoft/gomail/"
)

// creating an authenticated mailer
var mailer gomail.Mailer = gomail.NewMailer(
  "[email protected]", // a real email address
  "abcdefghijklmnop", // email password or an app password
  gomail.HOST.gmail, // an email host
  "MyName <[email protected]>", // (optional) Custom Name to send emails as by default
  // Note: A custom name Must be a valid alias in gmail or may be required with your host of choice
)

// custom host
var gmailHost gomail.Host = gomail.NewHost("smtp.gmail.com", "587")


// sending an email
func main(){
  mailer.send(
    []string{"[email protected]", "[email protected]"}, // list of emails to send to
    "My Email Subject",
    "My Email Body",
    gomail.MIME.html, // (optional) default: html
  )

  mailer.sendFrom(
    "Support <[email protected]>", // change the alias an email is sent from in place of the default
    []string{"[email protected]", "[email protected]"},
    "My Email Subject",
    "My Email Body",
    gomail.MIME.text,
  )

  mailer.send(
    []string{"[email protected]"},
    "Test Email",
    "<h1>Hello, Email!</h1>",
    "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";",
  )
}

GitHub

View Github