mail

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Purpose: This file implements the GoMail email sending component. It provides an interface and implementation for sending rich text and HTML emails via SMTP.

Philosophy: Email sending is a core utility for user communication (verification, reset, notifications). We provide a production-ready, pure standard library implementation based on `net/smtp`. This adheres to our zero-dependency framework core while providing a clean, ergonomic API that handles all low-level SMTP formatting and handshakes.

Architecture: The mailer exposes a `Mailer` struct which is initialized with `Config`. The global `gostack.Mail` facade allows easy application-wide usage. The mail component defines a `Message` representing SMTP metadata and payload (To, CC, Subject, Body, HTML).

Choice: We chose a direct `net/smtp.SendMail` wrapper because it is fast, simple, and is part of the Go stdlib. By wrapping it, we support standard auth types (like Plain Auth) and structure the headers/body automatically to avoid common issues with MIME formatting.

Implementation: - Config: holds SMTP server information (Host, Port, Username, Password, FromAddress, FromName). - Message: represents the details of an email to be sent. - Mailer: holds config and provides Send() method. - Send(msg Message): translates Message into raw RFC 822 format, establishes connection, authenticates, and sends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host        string
	Port        int
	Username    string
	Password    string
	FromAddress string
	FromName    string
}

Config defines the configuration properties required to connect to an SMTP server.

type Mailer

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

Mailer handles SMTP email dispatch.

func NewMailer

func NewMailer(cfg Config) *Mailer

NewMailer creates a new Mailer instance.

func (*Mailer) BuildRaw

func (m *Mailer) BuildRaw(msg Message) []byte

BuildRaw formats the Message into a raw SMTP bytes payload with correct headers.

func (*Mailer) Send

func (m *Mailer) Send(msg any) error

Send formats and sends the given Message via SMTP. It accepts any to satisfy contract.Mailer.

type Message

type Message struct {
	To      []string
	CC      []string
	Subject string
	Body    string
	IsHTML  bool
}

Message represents an individual email message.

Jump to

Keyboard shortcuts

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