go-easymail

command module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 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

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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