mail

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mail provides email sending functionality for Omnom notifications.

This package handles SMTP-based email delivery for various application events:

  • User login tokens (passwordless authentication)
  • Feed update notifications
  • System alerts

It supports both HTML and plain text email formats using template-based rendering. Templates are embedded in the application and loaded from the templates/mail directory.

The package maintains a persistent SMTP connection that is reused across multiple sends for efficiency. If the connection is lost, it automatically reconnects. Email sending can be disabled entirely by leaving the SMTP host empty in configuration.

Configuration supports:

  • Standard SMTP authentication
  • TLS/SSL encryption
  • Configurable timeouts
  • Custom sender addresses

Example usage:

err := mail.Init(cfg)
if err != nil {
    log.Fatal(err)
}

err = mail.Send(
    "user@example.com",
    "Welcome to Omnom",
    "welcome",
    map[string]any{"username": "john"},
)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemplateNotFound is returned when a mail template cannot be found.
	ErrTemplateNotFound = errors.New("mail template not found")
)

Functions

func Disable

func Disable(t bool)

Disable enables or disables mail sending.

func Init

func Init(c *config.Config) error

Init initializes the mail client and loads templates.

func Send

func Send(to string, subject string, msgType string, args map[string]any) error

Send sends an email using the specified template.

func SetSender

func SetSender(s string)

SetSender sets the sender email address.

Types

type Templates

type Templates struct {
	Text *text.Template
	HTML *html.Template
}

Templates holds HTML and text email templates.

func (*Templates) RenderHTML

func (t *Templates) RenderHTML(tname string, args map[string]any) (string, error)

RenderHTML renders html template with given arguments.

func (*Templates) RenderText

func (t *Templates) RenderText(tname string, args map[string]any) (string, error)

RenderText renders text template with given arguments.

Jump to

Keyboard shortcuts

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