mail

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// YandexPreset defines SMTP configuration and size limits for Yandex Mail.
	// Limits: Max message size is 30MB (including MIME encoding). Safe total attachments size is 22MB.
	// Yandex does not strictly clip HTML body at 102KB, but keeping it under 102KB is recommended.
	YandexPreset = ProviderPreset{
		Host:                    "smtp.yandex.ru",
		Port:                    465,
		UseSSL:                  true,
		MaxAttachmentSize:       22 * 1024 * 1024,
		MaxTotalAttachmentsSize: 22 * 1024 * 1024,
		MaxHTMLSize:             102 * 1024,
	}

	// GmailPreset defines SMTP configuration and size limits for Google Gmail.
	// Limits: Max message size is 25MB. Safe total attachments size is 18MB.
	// Gmail strictly clips HTML body exceeding 102KB.
	GmailPreset = ProviderPreset{
		Host:                    "smtp.gmail.com",
		Port:                    587,
		UseSSL:                  false,
		MaxAttachmentSize:       18 * 1024 * 1024,
		MaxTotalAttachmentsSize: 18 * 1024 * 1024,
		MaxHTMLSize:             102 * 1024,
	}

	// MailRuPreset defines SMTP configuration and size limits for Mail.ru.
	// Limits: Max message size is 25MB. Safe total attachments size is 18MB.
	MailRuPreset = ProviderPreset{
		Host:                    "smtp.mail.ru",
		Port:                    465,
		UseSSL:                  true,
		MaxAttachmentSize:       18 * 1024 * 1024,
		MaxTotalAttachmentsSize: 18 * 1024 * 1024,
		MaxHTMLSize:             102 * 1024,
	}

	// OutlookPreset defines SMTP configuration and size limits for Outlook/Office365.
	// Limits: Max message size is 25MB. Safe total attachments size is 18MB.
	OutlookPreset = ProviderPreset{
		Host:                    "smtp.office365.com",
		Port:                    587,
		UseSSL:                  false,
		MaxAttachmentSize:       18 * 1024 * 1024,
		MaxTotalAttachmentsSize: 18 * 1024 * 1024,
		MaxHTMLSize:             102 * 1024,
	}
)

Functions

func DecryptAES added in v0.0.2

func DecryptAES(key []byte, ciphertext []byte) ([]byte, error)

DecryptAES decrypts ciphertext bytes using AES-256-GCM.

func EncryptAES added in v0.0.2

func EncryptAES(key []byte, plaintext []byte) ([]byte, error)

EncryptAES encrypts plaintext bytes using AES-256-GCM.

Types

type Attachment added in v0.0.2

type Attachment struct {
	Filename      string
	ContentType   string
	ContentID     string
	Data          []byte
	IsInline      bool
	S3Key         string // Stored S3 reference key
	DecryptionKey []byte // Symmetric decryption key (AES-256-GCM)
}

Attachment represents a file embedded as an inline CID or standard attachment in the HTML email.

type AttachmentStore added in v0.0.2

type AttachmentStore interface {
	UploadAttachment(key string, data []byte) error
	DownloadAttachment(key string) ([]byte, error)
	DeleteAttachment(key string) error
}

AttachmentStore is a self-hosted S3/MinIO/Local abstraction for temporary attachment storage.

type MessageBuilder

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

MessageBuilder is a fluent builder for email messages.

func NewMessage

func NewMessage() *MessageBuilder

NewMessage creates a new fluent MessageBuilder.

func (*MessageBuilder) AddQueuedAttachment added in v0.0.2

func (m *MessageBuilder) AddQueuedAttachment(s3Key string, aesKey []byte, filename string, contentType string, isInline bool, cid string) *MessageBuilder

AddQueuedAttachment registers a deferred encrypted S3/AttachmentStore file reference.

func (*MessageBuilder) AttachBytes added in v0.0.2

func (m *MessageBuilder) AttachBytes(data []byte, filename string, contentType string) *MessageBuilder

AttachBytes registers raw binary data as a standard email attachment.

func (*MessageBuilder) AttachFile added in v0.0.2

func (m *MessageBuilder) AttachFile(filePath string) *MessageBuilder

AttachFile reads a local file and registers it as a standard email attachment.

func (*MessageBuilder) Body

func (m *MessageBuilder) Body(body string) *MessageBuilder

Body sets the plain-text mail body payload.

func (*MessageBuilder) EmbedBytes added in v0.0.2

func (m *MessageBuilder) EmbedBytes(data []byte, filename string, contentType string, cidName string) *MessageBuilder

EmbedBytes registers raw binary data as an inline CID attachment.

func (*MessageBuilder) EmbedFile added in v0.0.2

func (m *MessageBuilder) EmbedFile(filePath string, cidName string) *MessageBuilder

EmbedFile reads a local file and registers it as an inline CID attachment.

func (*MessageBuilder) Error

func (m *MessageBuilder) Error() error

Error returns the accumulated error if any, supporting sticky error check.

func (*MessageBuilder) EstimateSize added in v0.0.9

func (m *MessageBuilder) EstimateSize() int64

EstimateSize returns the estimated total size of the raw MIME email (in bytes).

func (*MessageBuilder) From

func (m *MessageBuilder) From(email, name string) *MessageBuilder

From configures the sender details.

func (*MessageBuilder) HTML added in v0.0.2

func (m *MessageBuilder) HTML(htmlContent string) *MessageBuilder

HTML sets the HTML formatted mail body payload.

func (*MessageBuilder) QueueAttachment added in v0.0.2

func (m *MessageBuilder) QueueAttachment(store AttachmentStore, aesKey []byte, filename string, contentType string, data []byte, isInline bool, cid string) (string, error)

QueueAttachment encrypts the file data using AES-256 GCM, uploads it to S3/AttachmentStore, and registers the deferred S3 Key in the builder automatically.

func (*MessageBuilder) Send

func (m *MessageBuilder) Send(config SMTPConfig) error

Send delivers the message using the provided SMTP server configuration.

func (*MessageBuilder) Subject

func (m *MessageBuilder) Subject(subject string) *MessageBuilder

Subject sets the mail subject header.

func (*MessageBuilder) To

func (m *MessageBuilder) To(emails ...string) *MessageBuilder

To appends target recipient emails.

func (*MessageBuilder) WithMaxAttachmentSize added in v0.0.5

func (m *MessageBuilder) WithMaxAttachmentSize(size int64) *MessageBuilder

WithMaxAttachmentSize overrides the default 10MB limit for a single attachment. A value of 0 or less disables the limit check for individual attachments.

func (*MessageBuilder) WithMaxHTMLSize added in v0.0.7

func (m *MessageBuilder) WithMaxHTMLSize(size int64) *MessageBuilder

WithMaxHTMLSize overrides the default 102KB limit for the HTML body markup size. A value of 0 or less disables the limit check.

func (*MessageBuilder) WithMaxTotalAttachmentsSize added in v0.0.5

func (m *MessageBuilder) WithMaxTotalAttachmentsSize(size int64) *MessageBuilder

WithMaxTotalAttachmentsSize overrides the default 25MB limit for the combined size of all attachments. A value of 0 or less disables the limit check for total attachments.

func (*MessageBuilder) WithPreset added in v0.0.6

func (m *MessageBuilder) WithPreset(preset ProviderPreset) *MessageBuilder

WithPreset applies the provider's standard attachment and total size limits to the builder.

func (*MessageBuilder) WithStore added in v0.0.2

func (m *MessageBuilder) WithStore(store AttachmentStore) *MessageBuilder

WithStore sets the AttachmentStore for S3 queueing support.

type ProviderPreset added in v0.0.6

type ProviderPreset struct {
	Host                    string
	Port                    int
	UseSSL                  bool
	MaxAttachmentSize       int64
	MaxTotalAttachmentsSize int64
	MaxHTMLSize             int64 // Maximum HTML body size to prevent Gmail email clipping (Gmail clips at 102KB)
}

ProviderPreset represents the SMTP configurations and size limits for popular mail providers.

func (ProviderPreset) SMTPConfig added in v0.0.6

func (p ProviderPreset) SMTPConfig(username, password string) SMTPConfig

SMTPConfig generates an SMTPConfig using the preset details and credentials.

type SMTPConfig

type SMTPConfig struct {
	Host                    string `json:"host"`
	Port                    int    `json:"port"`
	Username                string `json:"username"`
	Password                string `json:"password"`
	From                    string `json:"from"`
	FromName                string `json:"from_name"`
	UseSSL                  bool   `json:"use_ssl"`
	MaxHTMLSize             int64  `json:"max_html_size"`
	MaxAttachmentSize       int64  `json:"max_attachment_size"`
	MaxTotalAttachmentsSize int64  `json:"max_total_attachments_size"`
}

SMTPConfig represents the SMTP server settings.

func (SMTPConfig) GetEffectiveLimits added in v0.0.9

func (c SMTPConfig) GetEffectiveLimits() (htmlLimit int64, attLimit int64, totalLimit int64)

GetEffectiveLimits returns the limits (in bytes) for HTML size, individual attachment, and total attachments. It checks host-based presets first, then overrides with custom values if specified in SMTPConfig.

Directories

Path Synopsis
mrml-compiler command

Jump to

Keyboard shortcuts

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