email

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package email allows to send email messages. The package is used internally by the mail package.

Index

Constants

View Source
const (
	// MaxLineLength is the maximum line length per RFC 2045
	MaxLineLength = 76
	// DefaultContentType is the default Content-Type according to RFC 2045, section 5.2
	DefaultContentType = "text/plain; charset=us-ascii"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Header      textproto.MIMEHeader
	Content     []byte
	HTMLRelated bool
}

Attachment is a struct representing an email attachment. Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question

type Email

type Email struct {
	ReplyTo     []string
	From        string
	To          []string
	Bcc         []string
	Cc          []string
	Subject     string
	Text        []byte
	HTML        []byte
	Sender      string
	Headers     textproto.MIMEHeader
	Attachments []*Attachment
	ReadReceipt []string
}

Email is the type used for email messages

func New

func New() *Email

New creates an Email, and returns the pointer to it.

func NewFromReader

func NewFromReader(r io.Reader) (*Email, error)

NewFromReader reads a stream of bytes from an io.Reader, r, and returns an email struct containing the parsed data. This function expects the data in RFC 5322 format.

func (*Email) Attach

func (e *Email) Attach(r io.Reader, filename string, contentType string) (*Attachment, error)

Attach is used to attach content from an io.Reader to the email.

func (*Email) AttachFile

func (e *Email) AttachFile(filename string) (*Attachment, error)

AttachFile is used to attach content to the email. It attempts to open the file referenced by filename and, if successful, creates an Attachment.

func (*Email) Bytes

func (e *Email) Bytes() ([]byte, error)

Bytes converts the Email object to a []byte representation, including all needed MIMEHeaders, boundaries, etc.

func (*Email) Send

func (e *Email) Send(address string, auth smtp.Auth, helo string) error

Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message

func (*Email) SendWithStartTLS

func (e *Email) SendWithStartTLS(address string, auth smtp.Auth, config *tls.Config, helo string) error

SendWithStartTLS sends an email over TLS using STARTTLS with an optional TLS config.

func (*Email) SendWithTLS

func (e *Email) SendWithTLS(address string, auth smtp.Auth, config *tls.Config, helo string) error

SendWithTLS sends an email over tls with an optional TLS config.