email

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package email provides sending email ability.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attachment

func Attachment(fd io.Reader, filename string) fw.Option

Attachment sets email attachment.

func Bcc

func Bcc(bcc ...string) fw.Option

Bcc sets email Bcc addresses.

func Cc

func Cc(cc ...string) fw.Option

Cc sets email Cc addresses.

func From

func From(from string) fw.Option

From sets email from address.

func HTMLContentType

func HTMLContentType() fw.Option

HTMLContentType sets HTML message type.

func LoginAuth

func LoginAuth(username, password string) smtp.Auth

LoginAuth implements smtp.Auth which provides "LOGIN" mechanisms.

func NewSender

func NewSender(smtpServer string, auth smtp.Auth, opt ...fw.Option) (sender fw.Sender, err error)

NewSender returns Sender which sends email. requires SMTP server address, like "smtp.gmail.com:587", smtp.Auth which you have to implements and defines how get throug authorization.

func PoolSize

func PoolSize(size int) fw.Option

PoolSize sets pool size.

func ServerName

func ServerName(name string) fw.Option

ServerName sets TLS Config of Server Name.

func Subject

func Subject(subject string) fw.Option

Subject sets email subject.

func SubjectFunc

func SubjectFunc(fn func() string) fw.Option

SubjectFunc sets email subject from the func returned.

func TextContentType

func TextContentType() fw.Option

TextContentType sets Text message type.

func Timeout

func Timeout(timeout time.Duration) fw.Option

Timeout sets timeout.

func To

func To(to ...string) fw.Option

To sets email To addresses.

Types

type Email

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

Email implements Sender which sends email.

func (*Email) Send

func (e *Email) Send(message io.Reader, opt ...fw.Option) (err error)

Send sends email which you have to provides io.Reader include message body, and few options which implements Option.

Example (Html)
package main

import (
	"log"
	"strings"

	fw "github.com/LiangXianSen/firewheel"
	"github.com/LiangXianSen/firewheel/sender/email"
)

func main() {
	var err error
	var sender fw.Sender

	if sender, err = email.NewSender(
		"smtp.gmail.com:587",
		email.LoginAuth("username", "password"),
	); err != nil {
		log.Fatal(err)
	}

	if err = sender.Send(
		strings.NewReader("<h1>Fancy HTML is supported, too!</h1>"),
		email.HTMLContentType(),
		email.Subject("email test"),
		email.From("test@gmail.com"),
		email.To("test@gmail.com", "example@gmail.com"),
		email.Bcc("example@gmail.com"),
		email.Cc("example@gmail.com"),
	); err != nil {
		log.Fatal(err)
	}
}
Output:

Example (Text)
package main

import (
	"log"
	"strings"

	fw "github.com/LiangXianSen/firewheel"
	"github.com/LiangXianSen/firewheel/sender/email"
)

func main() {
	var err error
	var sender fw.Sender

	if sender, err = email.NewSender(
		"smtp.gmail.com:587",
		email.LoginAuth("username", "password"),
	); err != nil {
		log.Fatal(err)
	}

	if err = sender.Send(
		strings.NewReader("test message"),
		email.TextContentType(),
		email.Subject("email test"),
		email.From("test@gmail.com"),
		email.To("test@gmail.com", "example@gmail.com"),
		email.Bcc("example@gmail.com"),
		email.Cc("example@gmail.com"),
	); err != nil {
		log.Fatal(err)
	}
}
Output:

Jump to

Keyboard shortcuts

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