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