Documentation ¶
Overview ¶
Package mail provides a simple mailer that sends emails using the SMTP protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoContent = errors.New("email must have either plain text or HTML body") ErrNoSubject = errors.New("email must have a subject") )
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct { Filename string Data io.Reader ContentType gomail.ContentType }
Attachment represents an email attachment
type Config ¶
type Config struct { // SMTP server configuration Host string // SMTP server host Port int // SMTP server port Username string // SMTP server username Password string // SMTP server password From string // From address AuthType string // Type of SMTP authentication (see the go-mail package for options). Default is LOGIN. TLSPolicy int // TLS policy for the SMTP connection (see the go-mail package for options). Default is opportunistic. // Template configuration TemplateFS fs.FS // File system for templates TemplatePath string // Path to the templates directory in the file system TemplateFuncMap template.FuncMap // Template function map that gets merged with the default function map from render // Retry configuration RetryCount int // Number of retry attempts for sending email RetryDelay time.Duration // Delay between retry attempts // HTML processor for processing HTML content HTMLProcessor HTMLProcessor // HTML processor for processing HTML content // Company/Branding BaseURL string // Base URL of the website CompanyAddress string // Company address CompanyName string // Company name LogoURL string // URL to the company logo SupportEmail string // Support email address WebsiteName string // Name of the website WebsiteURL string // URL to the company website. // Links SiteLinks map[string]string // Site links SocialMediaLinks map[string]string // Social media links }
Config holds the mailer configuration
type DefaultHTMLProcessor ¶
type DefaultHTMLProcessor struct{}
DefaultHTMLProcessor provides a pass-through implementation
type EmailMessage ¶
type EmailMessage struct { To StringList // List of recipient email addresses Templates StringList // List of template names to proccess TemplateData any // Data to be passed to the templates Attachments []Attachment // List of attachments }
EmailMessage represents the content and recipients of an email
type HTMLProcessor ¶
HTMLProcessor defines the interface for processing HTML content
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
Mailer handles email sending operations
func (*Mailer) NewTemplateData ¶
func (m *Mailer) NewTemplateData() TemplateData
NewTemplateData creates a new template data map with default values
func (*Mailer) Send ¶
func (m *Mailer) Send(msg *EmailMessage) error
Send sends an email using the provided template and data
type TemplateData ¶
func NewTemplateData ¶
func NewTemplateData(cfg *Config) TemplateData
func (TemplateData) Merge ¶
func (td TemplateData) Merge(data map[string]any) TemplateData
Merge combines the current TemplateData with the provided data map.
func (TemplateData) MergeKeys ¶
func (td TemplateData) MergeKeys(data map[string]any) TemplateData
MergeKeys merges data into the template data, combining maps for existing keys instead of overwriting the entire map. This allows for more granular updates. It can merge maps for existing keys as well as add new keys.
Directories ¶
Path | Synopsis |
---|---|
Package notifications provides example email notifications.
|
Package notifications provides example email notifications. |