liam

package module
v0.0.0-...-ba93f7d Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 11 Imported by: 0

README

Go Report Card GoDoc

liam is a mail library which provides a set of extensions on go's standard net/smtp library,

so all interfaces are just a syntax sugar on the standard ones.

Major additional concepts are:

  • SOE: Simple, Original, Extended

  • liam.Send() to quick result

Usage

Simple

    package main
    
    import (
        "github.com/aaapi-net/liam"
    )

    err := liam.Send("mail.aaapi.net", 587, "from@aaapi.net", "p@ssw0rd", "to@aaapi.net", "Hello", "World!")

Extended

    package main

    import (
        "github.com/aaapi-net/liam"
    )

	err := liam.
		Smtp("mail.aaapi.net", 587).
		Auth("from@aaapi.net", "p@ssw0rd").
		AddTo("to@aaapi.net").
		Subject("Hello").
                Struct(&Message{Head: "Hello", Body: "World", Footer:"!"}).AsTemplate("{{ .Head }}\r\n{{ .Body }}\r\n{{ .Footer }}")
		Send()
package main

import (
	"fmt"
	"github.com/aaapi-net/liam"
)

var mail = liam.
		Smtp("mail.aaapi.net", 587).
		Auth("from@aaapi.net", "p@ssw0rd").
		AddTo("to@aaapi.net")


func main() {
	err := mail.
		Subject("Hello").
		Template(
			map[string]interface{}{
				"Username": "Dave", 
				"Type": "a new client",
			}, 
			`Hello {{ .Username }}, your are {{ .Type }}.`).
		Send()

	fmt.Println(err)
}

Alternatives:

https://github.com/xhit/go-simple-mail

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(server string, port int, username, password, emailTo, title, message string) error

secure: false

Types

type LMail

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

func (*LMail) AddCopyTo

func (lm *LMail) AddCopyTo(cc ...string) *LMail

func (*LMail) AddTo

func (lm *LMail) AddTo(to ...string) *LMail

func (*LMail) Sender

func (lm *LMail) Sender(sender string) *LMail

func (*LMail) SetCopyTo

func (lm *LMail) SetCopyTo(cc []string) *LMail

func (*LMail) SetTo

func (lm *LMail) SetTo(to []string) *LMail

func (*LMail) Struct

func (lm *LMail) Struct(body interface{}) *MailStruct

func (*LMail) Subject

func (lm *LMail) Subject(subject string) *LMail

func (*LMail) Template

func (lm *LMail) Template(body map[string]interface{}, template string) *MailTemplate

var body = map[string]interface{}{"Username": "Dave", "Type": "a new client"}

var template = `Hello {{ .Username }}, your are {{ .Type }}.`

The name of a key of the data, which must be a map, preceded

by a period, such as
  .Key
The result is the map element value indexed by the key.
Key invocations may be chained and combined with fields to any
depth:
  .Field1.Key1.Field2.Key2
Although the key must be an alphanumeric identifier, unlike with
field names they do not need to start with an upper case letter.
Keys can also be evaluated on variables, including chaining:
  $x.key1.key2

func (*LMail) Text

func (lm *LMail) Text(body interface{}) *MailText

type LSmtp

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

func Smtp

func Smtp(server string, port int) *LSmtp

secure: false

func (*LSmtp) Auth

func (ls *LSmtp) Auth(username string, password string) *LMail

type Liam

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

func New

func New() *Liam

secure: false

func NewClient

func NewClient(tlsConfig *tls.Config) *Liam

func NewConfig

func NewConfig(secure bool) *Liam

func (*Liam) Smtp

func (l *Liam) Smtp(server string, port int) *LSmtp

secure: false

type MailJson

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

func (*MailJson) Send

func (mj *MailJson) Send() (err error)

type MailStruct

type MailStruct struct {
	MailText
}

func (*MailStruct) AsJson

func (ms *MailStruct) AsJson() *MailJson

func (*MailStruct) AsTemplate

func (ms *MailStruct) AsTemplate(template string) *MailTemplate

type MailTemplate

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

TODO: html template

func (*MailTemplate) Send

func (mt *MailTemplate) Send() (err error)

type MailText

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

func (*MailText) Send

func (ms *MailText) Send() (err error)

Jump to

Keyboard shortcuts

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