Documentation
¶
Index ¶
- type Attachment
- type Client
- type EncryptionType
- type FileOption
- type Mailer
- type Message
- func (m *Message) AddAttachment(path string, opts ...FileOption) error
- func (m *Message) AddAttachmentData(filename string, content []byte, contentType string) *Message
- func (m *Message) AddBcc(emails ...string) *Message
- func (m *Message) AddCc(emails ...string) *Message
- func (m *Message) AddTo(emails ...string) *Message
- func (m *Message) Bytes() ([]byte, error)
- func (m *Message) SetBody(contentType, body string) *Message
- func (m *Message) SetFrom(from string) *Message
- func (m *Message) SetSubject(subject string) *Message
- func (m *Message) Validate() error
- type MockClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
Attachment represents an email attachment.
func CreateAttachmentFromFile ¶
func CreateAttachmentFromFile(path string, opts ...FileOption) (*Attachment, error)
CreateAttachmentFromFile creates an Attachment from a file path. It reads the file content and sets the filename.
func (*Attachment) Base64 ¶
func (a *Attachment) Base64() string
Base64 returns the base64 encoded content of the attachment.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an SMTP client.
type EncryptionType ¶
type EncryptionType string
EncryptionType defines the type of encryption to use for the SMTP connection.
const ( // EncryptionNone uses no encryption. EncryptionNone EncryptionType = "NONE" // EncryptionSSL uses implicit SSL/TLS (usually port 465). EncryptionSSL EncryptionType = "SSL" // EncryptionTLS uses explicit TLS (STARTTLS, usually port 587). EncryptionTLS EncryptionType = "TLS" )
type FileOption ¶
type FileOption func(*Attachment)
FileOption defines options for attaching files.
func WithFileName ¶
func WithFileName(name string) FileOption
WithFileName overrides the filename of the attachment.
type Mailer ¶
Mailer defines an interface for sending emails. It is useful for dependency injection and testing.
type Message ¶
type Message struct {
From string
To []string
Cc []string
Bcc []string
Subject string
Body string
ContentType string // "text/plain" or "text/html"
Attachments []*Attachment
}
Message represents an email message.
func NewMessage ¶
func NewMessage() *Message
NewMessage creates a new empty message. Default Content-Type is text/plain.
func (*Message) AddAttachment ¶
func (m *Message) AddAttachment(path string, opts ...FileOption) error
AddAttachment adds an attachment from a file path.
func (*Message) AddAttachmentData ¶
AddAttachmentData adds an attachment from bytes.
func (*Message) SetSubject ¶
SetSubject sets the email subject.
type MockClient ¶
MockClient is a mock implementation of Client for testing purposes.
func (*MockClient) Send ¶
func (m *MockClient) Send(messages ...*Message) error
Send records the sent messages and returns any configured error.