courier

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

courier

made-with-Go GitHub go.mod Go version GitHub GoReportCard GitHub release (latest SemVer)

courier is an email library with a different metaphor and for simplicity.

Basic usage:

package main


import (
	"github.com/markgemmill/courier"
	"github.com/markgemmill/courier/params"
)

func main () {
	
    message := params.Parameters{
        CourierParams: params.CourierParams{
            Host:     "mail.smtphost.com",
            Port:     2525,
            User:     "smtpUserId",
            Password: "smtpUserPwd",
        },
        EnvelopParams: params.EnvelopParams{
            SendFrom: "sender@senderhost.org",
            ReplyTo:  "reply@senderhost.org",
            SendTo:   []string{"getit@emailtown.com"},
            SendCc:   []string{"also@emailtown.com"},
        },
        MessageParams: params.MessageParams{
            HighPriority: true,
			TemplateType: "pongo",
            Subject:      "A Subject Worth Sending",
            Attachments:  []string{"/pth/to/attachment.doc"},
        },
    }

    params.SetMessage(&message, "<h1>Hello {{ name }}</h1>", true)
    params.SetTemplateData(&message, map[string]string{"name": "Courier!"})

    err := courier.Deliver(message)

    if err != nil {
        panic(err)
    }

}

For more verbose usage:

package main

import (
    "github.com/markgemmill/courier/guild"
    "github.com/markgemmill/courier/params"
)


func main() {
        
    // create the envelope
    envelope := guild.NewEnvelope()
    envelope.SetFromAddress("henry@england.com")
    envelope.AddToAddress("charels@france.com")
    envelope.AddCcAddress("walsingham@england.com")

    if envelope.HasErrors() {
        panic(envelope.GetErrors())
    }

    // create a scribe to define the message content and format
    scribe := guild.NewSimpleTextScribe() 
	scribe.SetPriority(true)
    scribe.SetSubjectTemplate("Give Up, or Else")
    scribe.SetTextBodyTemplate("It's mine and I'll come get it if I have to!")


    // start the scribe writing the message
    _, err := scribe.Open()
	if err != nil {
		panic(err)
    }

    scribe.Compose().Seal(envelope)

    if scribe.HasErrors() {
        panic(scribe.GetErrors())
    }

    courier := guild.NewCourier("smtpservice.org", 2525, "royalc", "seekrit")

    err = courier.Deliver(scribe.Message())
	
	if err != nil {
		panic(err)
    }
}

courier is built on top of the following libraries:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deliver

func Deliver(p params.Parameters) error

Deliver is the only function that is needed to send an email.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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