mailer

package
v1.6.15 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mailer sends transactional emails. If RESEND_API_KEY is set it uses the Resend HTTP API (recommended for cloud servers). Otherwise it falls back to Gmail SMTP — requires SMTP_USER + SMTP_PASS. If neither is configured every Send call is a no-op log (useful for local dev).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminAlertHTML added in v1.6.3

func AdminAlertHTML(title, details, actionLabel, actionURL string) string

AdminAlertHTML builds a simple admin alert email body.

Types

type Config

type Config struct {
	// Resend (preferred — works on DigitalOcean, no port blocks)
	ResendKey  string // RESEND_API_KEY  e.g. "re_..."
	ResendFrom string // e.g. "Mekong Tunnel <noreply@angkorsearch.dev>"

	// SMTP fallback (Gmail STARTTLS port 587)
	Host string // default: smtp.gmail.com
	Port string // default: 587
	User string // Gmail address
	Pass string // Gmail App Password
	From string // display name + address

	// AdminEmail receives operational alert emails (new signups, requests, etc.)
	AdminEmail string // ADMIN_NOTIFY_EMAIL
}

Config holds credentials for either Resend or SMTP.

type Mailer

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

Mailer sends emails.

func New

func New(cfg Config) *Mailer

New returns a ready Mailer with sensible defaults.

func (*Mailer) Enabled

func (m *Mailer) Enabled() bool

Enabled reports whether any email backend is configured.

func (*Mailer) NotifyAdmin added in v1.6.3

func (m *Mailer) NotifyAdmin(subject, htmlBody string)

NotifyAdmin sends an operational alert email to the configured AdminEmail. If AdminEmail is not set, the call is a no-op.

func (*Mailer) Send

func (m *Mailer) Send(to, subject, htmlBody string) error

Send delivers an HTML email. Uses Resend if key is set, else SMTP.

func (*Mailer) SendInvitation added in v1.5.8

func (m *Mailer) SendInvitation(toEmail, inviterEmail, teamName, token, frontendURL string)

SendInvitation sends a team invitation email with an accept link.

func (*Mailer) SendLoginOTP

func (m *Mailer) SendLoginOTP(toEmail, name, code string)

SendLoginOTP sends a 6-digit login verification code to the user's email.

func (*Mailer) SendNewsletter

func (m *Mailer) SendNewsletter(toEmail, name, subject, bodyHTML string)

SendNewsletter sends a newsletter campaign to a single recipient. Called in a goroutine per recipient from the admin send handler.

func (*Mailer) SendPasswordReset

func (m *Mailer) SendPasswordReset(toEmail, name, token, frontendURL string)

SendPasswordReset sends the password-reset link.

func (*Mailer) SendPlanExpiryWarning added in v1.6.3

func (m *Mailer) SendPlanExpiryWarning(toEmail, name string, expiresAt time.Time, frontendURL string)

SendPlanExpiryWarning emails a student whose plan expires within the next week.

func (*Mailer) SendProvisionedWelcome added in v1.5.8

func (m *Mailer) SendProvisionedWelcome(toEmail, name, orgName, tempPassword, frontendURL string)

SendProvisionedWelcome sends a welcome email to a user provisioned by an org admin.

func (*Mailer) SendVerification

func (m *Mailer) SendVerification(toEmail, name, token, frontendURL string)

SendVerification sends the email-verification link.

Jump to

Keyboard shortcuts

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