eazymail

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 7 Imported by: 0

README

GO Easy Email

This package is a simple go-mail wrapper for direct or lazy send emails. The Emailer Interface needs two Methods for initializing go-mail. It sends formatted html mails if you put html tags inside.

Interface
type Emailer interface {
	Send(sender, recipient, subject, body string) error
	newEmail() *mail.Client
}
Direct Mail Init
var e Emailer
e = NewEmail(os.Getenv("SMTPSERVER"), os.Getenv("SMTPUSER"), os.Getenv("SMTPPASSWORD"))
e.Send(RecipientName, RecpientEmail, Subject, Message)

Lazy Mail Init

The LazyMail structure runs a background job from the start of initializing it until the main application ends. You can inject your own method to handle the background job from the start or just take basicEmailSend. It takes the interval as milliseconds how often it should dequeue a message from the email queue and send it via go-mail. For unit testing there is although lazyunittest which i used to similuate the dequeing in time.

var e Emailer
e = NewLazymail(os.Getenv("SMTPSERVER"), os.Getenv("SMTPUSER"), os.Getenv("SMTPPASSWORD"), basicEmailSend(1000))
e.Send(RecipientName, RecpientEmail, Subject, Message)

Running from Command Line

SMTPSERVER=smtp.foo.com SMTPUSER=user@foo.com SMTPPASSWORD=secret RECNAME=foobar ENDER RECMAIL=foobar@foobar.com SUBJECT="Subject" MESSAGE="message" go run .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicEmailSend

func BasicEmailSend(seconds int) func(l *LazyMail)

func SendUpToEightEmailsAndThenDelay

func SendUpToEightEmailsAndThenDelay(seconds int) func(l *LazyMail)

Types

type ConcurrentQueue

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

func NewConcurrentQueue

func NewConcurrentQueue(length, capacity int) ConcurrentQueue

type Email

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

func NewEmail

func NewEmail(smtpserver, username, password string) *Email

func (*Email) Send

func (e *Email) Send(sender, recipient, subject, body string) error

func (*Email) SendWithFile added in v0.0.3

func (e *Email) SendWithFile(sender, recipient, subject, body string, filenames ...string) error

type Emailer

type Emailer interface {
	Send(sender, recipient, subject, body string) error
	SendWithFile(sender, recipient, subject, body string, filenames ...string) error
	// contains filtered or unexported methods
}

type LazyMail

type LazyMail struct {
	BackgroundJob func(l *LazyMail)
	// contains filtered or unexported fields
}

func NewLazymail

func NewLazymail(smtpserver, username, password string, behavior func(l *LazyMail)) *LazyMail

func (*LazyMail) Send

func (l *LazyMail) Send(sender, recipient, subject, body string) error

func (*LazyMail) SendWithFile added in v0.0.5

func (l *LazyMail) SendWithFile(sender, recipient, subject, body string, filenames ...string) error

type Message

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

type Stack

type Stack []Message

func (*Stack) Peek

func (s *Stack) Peek() (Message, error)

func (*Stack) Pop

func (s *Stack) Pop() (Message, error)

func (*Stack) Push

func (s *Stack) Push(val Message)

Jump to

Keyboard shortcuts

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