email

package
v6.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

MailService

MailService provides the basic ability to send email.

Example
service := email.NewMailService(email.Config{
	Host: "mail.something.com",
	Password: "password",
	Port: 25,
	UserName: "user",
})

if err = service.Connect(); err != nil {
	// Handle error
}

mail := email.Mail{
	Body: "This is an example",
	From: email.Person{
		Name: "Adam",
		EmailAddress: "test@test.com",
	},
	Subject: "This is a sample",
	To: []Person{
		{
			Name: "Bob Hope",
			EmailAddress: "address1@test.com",
		},
		{
			Name: "Elvis Presley",
			EmailAddress: "address2@test.com",
		},
	},
}

if err = service.Send(mail); err != nil {
	// Handle error
}
Validating Email Address
isValid = email.IsValidEmailAddress("whatever")
// isValid == false

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidEmailAddress

func IsValidEmailAddress(email string) bool

IsValidEmailAddress returns true/false if a provided email address is valid

Types

type Config

type Config struct {
	Host     string
	Password string
	Port     int
	UserName string
}

A Config object tells us how to configure our email server connection

type IMailService

type IMailService interface {
	Connect() error
	Send(mail ...Mail) error
}

IMailService provides an interface describing a service for working with email

type Mail

type Mail struct {
	Body    string
	From    Person
	Subject string
	To      []Person
}

Mail represents an email. Who's sending, recipients, subject, and message

type MailService

type MailService struct {
	Config *Config
	Dialer *gomail.Dialer
	Sender gomail.SendCloser
}

MailService provides methods for working with email

func NewMailService

func NewMailService(config *Config) *MailService

NewMailService creates a new instance of MailService

func (MailService) Connect

func (s MailService) Connect() error

Connect establishes a connections to an SMTP server

func (MailService) Send

func (s MailService) Send(mail ...Mail) error

Send sends an email

type Person

type Person struct {
	Name         string
	EmailAddress string
}

A Person is someone who sends or receives email

Jump to

Keyboard shortcuts

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