mail

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 16 Imported by: 2

Documentation

Overview

https://github.com/scorredoira/email

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Receipt

func Receipt(name, address string) *mail.Address

Receipt creates a mail.Address pointer from name and address.

Types

type Attachment

type Attachment struct {
	Filename  string
	Path      string
	Bytes     []byte
	ContentID string
}

Attachment represents an email attachment

type ContentType

type ContentType int

ContentType represents content type

const (
	// TextPlain sets body type to text/plain in message body
	TextPlain ContentType = iota
	// TextHTML sets body type to text/html in message body
	TextHTML
)

func (ContentType) String

func (contentType ContentType) String() string

type Dialer

type Dialer struct {
	Server   string
	Port     int
	TLS      bool
	Account  string
	Password string
	Timeout  time.Duration
}

Dialer is a dialer to an SMTP server.

func (*Dialer) Dial

func (d *Dialer) Dial() (client *smtp.Client, err error)

Dial dials the SMTP server and performs optional STARTTLS / AUTH. It returns a connected smtp.Client. Caller should call client.Quit() when done.

func (*Dialer) Send

func (d *Dialer) Send(msg ...*Message) error

Send sends the given messages using one established connection. It honors Dialer.Timeout for each message via context timeouts. The client connection will be Quit() when Send returns.

func (*Dialer) SendMail

func (d *Dialer) SendMail(ctx context.Context, from string, to []string, msg []byte) error

SendMail connects to the server at Dialer's addr, switches to TLS if possible, authenticates with the optional mechanism a if possible, and then sends an email from address from, to addresses to, with message msg.

The addresses in the to parameter are the SMTP RCPT addresses.

The msg parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of msg should be CRLF terminated. The msg headers should usually include fields such as "From", "To", "Subject", and "Cc". Sending "Bcc" messages is accomplished by including an email address in the to parameter but not including it in the msg headers.

type Message

type Message struct {
	From        *mail.Address
	To, Cc, Bcc Receipts
	Subject     string
	Body        string
	ContentType ContentType
	Attachments []*Attachment
}

Message represents an email message

func (*Message) Bytes

func (m *Message) Bytes(id string) []byte

Bytes renders the RFC822-style message bytes for the message. id is used to create the Message-ID domain if provided; if empty, fallback to hostname. The produced message uses CRLF line endings as required by SMTP and includes correct MIME headers for single-part or multipart/mixed with attachments.

func (*Message) RcptList

func (m *Message) RcptList() (rcpts []string)

RcptList returns a de-duplicated list of recipient email addresses while preserving order: first To, then Cc, then Bcc.

type Receipts

type Receipts []*mail.Address

Receipts represents a list of mail addresses.

func ParseReceipts

func ParseReceipts(rcpts string) (Receipts, error)

ParseReceipts parses a comma/semicolon separated list of addresses into Receipts.

func (Receipts) List

func (rcpts Receipts) List() []string

List returns a slice of address strings (just the email addresses).

func (Receipts) MarshalJSON

func (rcpts Receipts) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It encodes the receipts as a JSON array of email address strings.

func (Receipts) MarshalText

func (rcpts Receipts) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler and returns the RFC5322 representation.

func (Receipts) String

func (rcpts Receipts) String() string

String returns the addresses joined in the standard RFC 5322 way using the String method of mail.Address.

func (*Receipts) UnmarshalJSON

func (rcpts *Receipts) UnmarshalJSON(b []byte) error

UnmarshalJSON supports either a single string (comma separated) or an array of strings.

func (*Receipts) UnmarshalText

func (rcpts *Receipts) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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