lightmail

package module
v0.0.0-...-161ee1d Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: MIT Imports: 9 Imported by: 0

README

LightMail

LightMail is a simple package to send text/plain or text/html mails via SMTP using the standard html/template and text/template packages.

Usage

In order to use this package you should be familiar with the following packages text/template and html/template.

Mail service instance

First a mail service instance is needed. To establish a connection to the smtp server, you need to specify the smtp settings.

config := lightmail.SMTPConfig{
   Server:      "smtp.mailserver.tld",
   Port:        "587",
   User:        "bob@mailserver.tld",
   Password:    "foo",
   TLSConfig:   &tls.Config{
                    InsecureSkipVerify: false,
                    ServerName:         "smtp.mailserver.tld",
                },
}

mailService := lightmail.NewMailService(&config)
Plain text mail instance

To send a plain text mail you need to create a new text mail instance using your text template reference.

func (s *MailService) NewTextMail(template *template.Template) *TextMail
HTML mail instance

To send a html mail you need to create a new html mail instance using your html template reference.

func (s *MailService) NewHTMLMail(template *template.Template) *HTMLMail
Execute Template

Next you need to execute your template.

func ExecuteTemplate(data interface{}) error
Send mail

Now just call the send method on your mail instance to send the mail using the mail service, where mail.Address is from the default go mail package.

func Send(from *mail.Address, to []*mail.Address, subject string) error
Dependencies

In order to work properly, this packages needs the follwoing third party packages installed in your GoPath.

  • github.com/google/uuid
  • github.com/oxtoacart/bpool
  • github.com/go-mail/mail

License

MIT licensed 2019 Cedrik Kaufmann. See the LICENSE file for further details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTMLMail

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

HTMLMail text/plain mail instance

func (*HTMLMail) ExecuteTemplate

func (mail *HTMLMail) ExecuteTemplate(data interface{}) error

ExecuteTemplates executes the associated template with the given data It returns an error or nil

func (*HTMLMail) Send

func (mail *HTMLMail) Send(from *mail2.Address, to []*mail2.Address, subject string) error

Send sends the executed template as text/hmtl mail It returns an error or nil

type Mail

type Mail interface {
	Send(from *mail.Address, to []*mail.Address, subject string) error
	ExecuteTemplate(data interface{}) error
}

type MailService

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

func NewMailService

func NewMailService(config *SMTPConfig) *MailService

func (*MailService) NewHTMLMail

func (s *MailService) NewHTMLMail(htmlTemplate *template2.Template, plainTemplate *template.Template) *HTMLMail

NewHTMLMail creates a new instance of a text/html mail It returns the instance

func (*MailService) NewTextMail

func (s *MailService) NewTextMail(template *template.Template) *TextMail

NewTextMail creates a new instance of a text/plain mail It returns the instance

type SMTPConfig

type SMTPConfig struct {
	Server    string
	Port      int
	Username  string
	Password  string
	TLSConfig *tls.Config
}

type TextMail

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

TextMail text/plain mail instance

func (*TextMail) ExecuteTemplate

func (mail *TextMail) ExecuteTemplate(data interface{}) error

ExecuteTemplates executes the associated template with the given data It returns an error or nil

func (*TextMail) Send

func (mail *TextMail) Send(from *mail2.Address, to []*mail2.Address, subject string) error

Send sends the executed template as text/plain mail It returns an error or nil

Jump to

Keyboard shortcuts

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