mailer

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mailer provides an abstraction for sending HTML emails It supports multiple sending backends (SMTP, API-based services), asynchronous sending, retry logic, and fallback to logging when no email provider is configured.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailer

type Mailer interface {
	SendRequestAuth(ctx context.Context, to, otp string) error
	SendAccountApproved(ctx context.Context, to string) error
	SendAccountBlocked(ctx context.Context, to string) error
	SendAccountReactivated(ctx context.Context, to string) error
}

Mailer defines the interface for sending templated emails.

func New

func New(cfg *config.Mailer) (Mailer, error)

New creates a new Mailer instance based on the provided config. Priority: SMTP > Resend > no-op fallback.

type NoOpTransport

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

NoOpTransport is a no-op transport that logs emails instead of sending them.

func NewNoOpTransport

func NewNoOpTransport(sender, replyTo string) (*NoOpTransport, error)

NewNoOpTransport creates a new no-op transport.

func (*NoOpTransport) Send

func (s *NoOpTransport) Send(_ context.Context, to, subject, text, html string) error

Send logs the email instead of sending it.

type ResendError

type ResendError struct {
	StatusCode int
	Name       string
	Message    string
}

ResendError represents an error returned by the Resend API.

func (*ResendError) Error

func (e *ResendError) Error() string

type ResendSender

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

ResendSender sends emails via the Resend API.

func NewResendSender

func NewResendSender(apiKey, sender, replyTo string) (*ResendSender, error)

NewResendSender creates a new Resend sender with the given API key. Returns an error if the API key is empty.

func (*ResendSender) Send

func (s *ResendSender) Send(ctx context.Context, to, subject, text, html string) error

Send sends an email via the Resend API.

type SMTPSender

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

SMTPSender sends emails via SMTP.

func NewSMTPSender

func NewSMTPSender(address, user, password, sender, replyTo string) (*SMTPSender, error)

NewSMTPSender creates a new SMTP sender with the given configuration.

func (*SMTPSender) Send

func (s *SMTPSender) Send(ctx context.Context, to, subject, text, html string) error

Send sends an email via SMTP.

type Transport

type Transport interface {
	Send(ctx context.Context, to, subject, text, html string) error
}

Transport defines the interface for sending emails via a backend service.

Jump to

Keyboard shortcuts

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