postbox

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

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

Go to latest
Published: Oct 30, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

README ¶

Postbox 📬

A small library for constructing RFC 2822 style multipart messages. This library could be used to interact with a SMTP server to send mail.

package main

import (
	"strings"

	"github.com/jeroenrinzema/postbox"
)

func main() {
	body := postbox.Part{
		ContentType: "message",
		Encoding:    postbox.Base64,
		Reader:      strings.NewReader("https://www.youtube.com/watch?v=dQw4w9WgXcQ"),
	}

	mail := postbox.Envelope{
		From:    "john@example.com",
		Sender:  "john@example.com",
		ReplyTo: "reply@example.com",
		To:      []string{"bil@example.com", "dan@example.com"},
		Subject: "Check this out!",
		Parts:   []*postbox.Part{&body},
	}
}

Documentation ¶

Index ¶

Constants ¶

View Source
const CR = "\r"

CR represents a ASCII CR

View Source
const CRLF = CR + LF

CRLF represents a ASCII CR+LF

View Source
const LF = "\n"

LF represents a ASCII LR

Variables ¶

This section is empty.

Functions ¶

func RandomBoundary ¶

func RandomBoundary() string

RandomBoundary generates a new random boundary

Types ¶

type Boundary ¶

type Boundary struct {
	Identifier string
	// contains filtered or unexported fields
}

Boundary represents a multipart boundary

func NewBoundary ¶

func NewBoundary(writer io.Writer, mime string) Boundary

NewBoundary starts a new multipart context and generates a new boundary. The headers are written to the given io.Writer.

func (*Boundary) End ¶

func (b *Boundary) End()

End marks the boundary as ended

func (*Boundary) Mark ¶

func (b *Boundary) Mark()

Mark appends the boundary identifier to the set io.Writer

type ContentType ¶

type ContentType string

ContentType and it's boundry

type Encoding ¶

type Encoding string

Encoding represents a MIME encoding scheme like quoted-printable or base64.

const (
	// QuotedPrintable represents the quoted-printable encoding as defined in
	// RFC 2045.
	QuotedPrintable Encoding = "quoted-printable"
	// Base64 represents the base64 encoding as defined in RFC 2045.
	Base64 Encoding = "base64"
	// Unencoded can be used to avoid encoding the body of an email. The headers
	// will still be encoded using quoted-printable encoding.
	Unencoded Encoding = "8bit"
)

type Envelope ¶

type Envelope struct {
	Date        time.Time // RFC 4021 2.1.1
	From        string    // RFC 4021 2.1.2
	Sender      string    // RFC 4021 2.1.3
	ReplyTo     string    // RFC 4021 2.1.4
	To          []string  // RFC 4021 2.1.5
	Cc          []string  // RFC 4021 2.1.6
	Subject     string    // RFC 4021 2.1.11
	Parts       []*Part   // RFC 1341 7.2
	Embedded    []*File   // RFC 2387
	Attachments []*File   // RFC 1341 7.2
	Charset     string
}

Envelope is responsible for the generation of RFC 822-style emails. Specifications mentioned: - RFC 2822 - Internet Message Format - RFC 2387 - The MIME Multipart/Related Content-type - RFC 1341 - MIME (Multipurpose Internet Mail Extensions) - RFC 4021 - Registration of Mail and MIME Header Fields

func (*Envelope) Write ¶

func (e *Envelope) Write(writer io.WriteCloser)

Write writes the smtp message as multiform to the given io.Writer

type File ¶

type File struct {
	Name     string
	Header   map[string][]string
	CopyFunc func(w io.Writer) error
}

File represents a multiform file

type Headers ¶

type Headers map[string][]string

Headers is a representation of a multiform part header

func (Headers) Write ¶

func (h Headers) Write(writer io.Writer)

Write writes the headers to the given io.Writer

type Part ¶

type Part struct {
	ContentType string
	Encoding    Encoding
	Reader      io.Reader
}

Part represents a multiform part

func (*Part) Write ¶

func (p *Part) Write(writer io.Writer, charset string)

Write writes the part to the given io writer

Jump to

Keyboard shortcuts

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