gomail

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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(
  "example@gmail.com", // a real email address
  "abcdefghijklmnop", // email password or an app password
  gomail.HOST.gmail, // an email host
  "MyName <noreply@example.com>", // (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{"user1@example.com", "user2@example.com"}, // list of emails to send to
    "My Email Subject",
    "My Email Body",
    gomail.MIME.html, // (optional) default: html
  )

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MIME mime = mime{
	Text:   "MIME-version: 1.0;\nContent-Type: text/plain; charset=\"UTF-8\";",
	Html:   "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";",
	Png:    "MIME-version: 1.0;\nContent-Type: image/png; charset=\"UTF-8\";",
	Jpeg:   "MIME-version: 1.0;\nContent-Type: image/jpeg; charset=\"UTF-8\";",
	Jpg:    "MIME-version: 1.0;\nContent-Type: image/jpg; charset=\"UTF-8\";",
	Mp4:    "MIME-version: 1.0;\nContent-Type: video/mp4; charset=\"UTF-8\";",
	Mp3:    "MIME-version: 1.0;\nContent-Type: audio/mp3; charset=\"UTF-8\";",
	Json:   "MIME-version: 1.0;\nContent-Type: application/json; charset=\"UTF-8\";",
	Msword: "MIME-version: 1.0;\nContent-Type: application/msword; charset=\"UTF-8\";",
}

Functions

This section is empty.

Types

type Host

type Host struct {
	Gmail MailHost
}
var HOST Host = Host{
	Gmail: MailHost{/* contains filtered or unexported fields */},
}

type MailHost

type MailHost struct {
	// contains filtered or unexported fields
}

func NewHost

func NewHost(host string, port string) MailHost

type Mailer

type Mailer struct {
	Send     func(to []string, subject string, body string, mime ...string) error
	SendFrom func(from string, to []string, subject string, body string, mime ...string) error
}

func NewMailer

func NewMailer(email string, pwd string, host MailHost, fromEmail ...string) (Mailer, error)

Jump to

Keyboard shortcuts

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