gomail

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

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 5 Imported by: 0

README

go-mail

GoDoc

go-mail creates a simple wrapper around [net/mail.Message] to extend common functionality.

Installing

$ go get -u github.com/codykaup/go-mail

Example

Reading a message
import (
	"bufio"
	"fmt"
	"os"

	mail "github.com/codykaup/go-mail"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	message, _ := mail.ReadMessage(reader)

	fmt.Printf("Headers: %+v\n", message.Header)
	fmt.Printf("Body: %+v\n", message.Body)
}
Append a header
import (
	"bufio"
	"fmt"
	"os"

	mail "github.com/codykaup/go-mail"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	message, _ := mail.ReadMessage(reader)

	fmt.Printf("Headers: %+v\n", message.Header)

	entry, _ := mail.NewHeaderEntry("Cc", "john@example.com")
	message.AppendHeader(entry)

	fmt.Printf("New Headers: %+v\n", message.Header)
}
Get the full message
import (
	"bufio"
	"fmt"
	"os"

	mail "github.com/codykaup/go-mail"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	message, _ := mail.ReadMessage(reader)

	fmt.Println(message.Join())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderEntry

type HeaderEntry struct {
	Key   string
	Value []string
}

func NewHeaderEntry

func NewHeaderEntry(fieldName, value string) (HeaderEntry, error)

NewHeaderEntry generates a new HeaderEntry after format validation

Validation is based on RFC-5322: https://tools.ietf.org/html/rfc5322

fieldName - The name of the field (like Date/From/Subject) value - The value for the field (use commas to signal multiple values)

type Message

type Message struct {
	Header mail.Header
	Body   string
}

func ReadMessage

func ReadMessage(src io.Reader) (Message, error)

ReadMessage reads the message and returns the Message value

func (*Message) AppendHeader

func (m *Message) AppendHeader(entry HeaderEntry) error

AppendHeader adds the new entry to the message header

func (*Message) Join

func (m *Message) Join() string

Join appends the body of the message to the header to display the full message

Jump to

Keyboard shortcuts

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