mimemail

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mimemail implements functionality for creating MIME email messages

Example
// let's assume that contains some image
var logo []byte
mixed := NewMultipart("multipart/mixed")
html := mixed.NewDiscrete("text/html", "charset", "utf-8")
html.Encoding(QuotedPrintable)
html.Content([]byte(`<html><body>
		<img src="cid:logo.png">
		<h1>Hi there!</h1></body></html>`))
img := mixed.NewDiscrete("image.png")
img.Encoding(Base64)
img.Header().Add("content-id", "logo.png")
img.Content(logo)
msg := NewMessage(mixed)
msg.Header().Add("Subject", "mimemail is here")
msg.Header().Add("From", "Sender <sender@example.com>")
msg.Header().Add("To", "Rcpt <recipient@example.com>")
w := bytes.NewBuffer(nil)
// this could be instead
// w, _ = smtpClient.Data()
if err := msg.Write(w); err != nil {
	panic(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discrete

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

Discrete is a discret entity that contains a single piece of content of certain type

func NewDiscrete

func NewDiscrete(ct string, param ...string) *Discrete

NewDiscrete returns a new Discrete object with given content type and content type parameters

func (*Discrete) Content

func (d *Discrete) Content(c []byte)

Content sets the content of the entity. Content should be given as raw bytes, it will be encoded automatically by Write method.

func (*Discrete) Encoding

func (d *Discrete) Encoding(e Encoding)

Encoding sets the content transfer encoding. Write will encode content using the given method.

func (*Discrete) Header

func (d *Discrete) Header() *Header

Header returns the header of the Discrete object

func (*Discrete) Write

func (d *Discrete) Write(w io.Writer) error

Write writes the Discrete entity including the header and content encoded according to chosen method to the writer

type Encoding

type Encoding int

Encoding is the content transfer encoding method

const (
	SevenBit Encoding = iota
	QuotedPrintable
	Base64
)
type Header struct {
	// contains filtered or unexported fields
}

Header is the header of the email message or a MIME entity

func NewHeader

func NewHeader() *Header

NewHeader returns a new header

func (*Header) Add

func (h *Header) Add(name, value string)

Add adds a field with the given name and the value to the header

func (*Header) Write

func (h *Header) Write(w io.Writer) error

Write writes the header to the writer

type Message

type Message struct {
	Part
}

Message represent an email message

func NewMessage

func NewMessage(part Part) *Message

NewMessage creates a new email message based on the provided part

type Multipart

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

Multipart is a composite entity that can contain multiple parts

func NewMultipart

func NewMultipart(ct string) *Multipart

NewMultipart returns new Multipart object

func (*Multipart) AddPart

func (mp *Multipart) AddPart(p Part)

AddPart adds a new part to the Multipart object

func (*Multipart) Header

func (mp *Multipart) Header() *Header

Header returns the header of the Multipart object

func (*Multipart) NewDiscrete

func (mp *Multipart) NewDiscrete(ct string, param ...string) *Discrete

NewDiscrete returns a new Discrete object that is already added as a part to the parent object

func (*Multipart) NewMultipart

func (mp *Multipart) NewMultipart(ct string) *Multipart

NewMultipart returns a new Multipart object that is already added as a part to the parent object

func (*Multipart) Write

func (mp *Multipart) Write(w io.Writer) error

Write writes the Multipart entity including the header and encoded content of all the parts to the writer

type Part

type Part interface {
	// Header returns the header of the email part
	Header() *Header
	// Write writes the part including the header and encoded content to the writer
	Write(io.Writer) error
}

Part is a part of the email message

Jump to

Keyboard shortcuts

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