mailer

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailTemplateData

type EmailTemplateData struct {
	AppName string
	BaseURL string
	UserId  int64
	Token   string
	Year    int
}

EmailTemplateData preserves the legacy data structure used by the built-in registration/password reset templates. New templates can use any custom data via RenderNamed.

type EmailType

type EmailType int

EmailType defines the type of email to send

const (
	// EmailTypeRegistration is for registration confirmation emails
	EmailTypeRegistration EmailType = iota
	// EmailTypePasswordReset is for password reset emails
	EmailTypePasswordReset
)

type MailNotification

type MailNotification struct {
	From    User
	To      User
	Html    string
	Subject string
}

type Mailer

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

func NewMailer

func NewMailer(provider Provider, template *Template, from User) *Mailer

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, id int64, email, token string, emailType EmailType) error

Send preserves legacy behavior for registration/password reset emails. For new email types, prefer SendTemplate which supports arbitrary templates and data.

func (*Mailer) SendTemplate

func (m *Mailer) SendTemplate(ctx context.Context, to User, subject, templateName string, data any) error

SendTemplate sends an email using a named template and arbitrary data and allows specifying any subject string.

type Provider

type Provider interface {
	Send(ctx context.Context, notify MailNotification) error
}

type Template

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

func NewEmailTemplate

func NewEmailTemplate(registrationFile, passwordResetFile, baseUrl, appName string, year int) (*Template, error)

func (*Template) AddTemplate

func (t *Template) AddTemplate(name, filePath string) error

AddTemplate parses and registers an additional template under a given name.

func (*Template) Render

func (t *Template) Render(id int64, token string, emailType EmailType) (string, error)

Render keeps backward compatibility with existing callers that expect registration/password reset emails. It internally maps to named templates and constructs legacy data.

func (*Template) RenderNamed

func (t *Template) RenderNamed(name string, data any) (string, error)

RenderNamed renders a template by its name with arbitrary data.

type User

type User struct {
	Email string
	Name  string
}

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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