Documentation
¶
Index ¶
- func NewQueuedMail(msg *Message, driver string) *queue.GenericJob[QueuedMailPayload]
- type Attachment
- type LogMailer
- type Mailable
- type MailableLayout
- type MailableSender
- type Mailer
- type Message
- type QueuedMailPayload
- type ResendMailer
- type SMTPMailer
- type TemplateMailer
- type TemplateMailerOption
- type TemplateRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewQueuedMail ¶
func NewQueuedMail(msg *Message, driver string) *queue.GenericJob[QueuedMailPayload]
NewQueuedMail creates a new background job for sending an email.
Types ¶
type Attachment ¶
Attachment represents a file attached to an email.
type LogMailer ¶
type LogMailer struct {
// contains filtered or unexported fields
}
LogMailer implements the Mailer interface by writing emails to a local file/log.
func NewLogMailer ¶
NewLogMailer creates a new LogMailer.
type Mailable ¶
type Mailable interface {
// Subject returns the email subject line.
Subject() string
// From returns the sender address (overrides mailer default if non-empty).
From() string
// To returns the list of recipient addresses.
To() []string
// Template returns the template name (without extension) relative to the
// email template directory (e.g. "emails/welcome").
Template() string
// Data returns the template data map.
Data() map[string]any
}
Mailable is the interface for structured, layout-aware HTML emails. Implement this to get automatic layout wrapping, data interpolation, and seamless integration with the notification package.
Example:
type WelcomeMail struct {
User schema.User
}
func (m *WelcomeMail) Subject() string { return "Welcome to Astra!" }
func (m *WelcomeMail) From() string { return "noreply@example.com" }
func (m *WelcomeMail) To() []string { return []string{m.User.Email} }
func (m *WelcomeMail) Template() string { return "emails/welcome" }
func (m *WelcomeMail) Data() map[string]any { return map[string]any{"User": m.User} }
type MailableLayout ¶
type MailableLayout interface {
Mailable
// Layout returns the layout template name relative to the email template
// directory (e.g. "layouts/email"). Return "" to disable layout.
Layout() string
}
MailableLayout optionally implemented by a Mailable to override the layout. If not implemented, the mailer's default layout is used.
type MailableSender ¶
MailableSender can send Mailable instances. Combine with TemplateMailer to get HTML rendering + delivery.
type Message ¶
type Message struct {
From string
To []string
Subject string
Body string
HTML string
Attachments []Attachment
}
Message represents an email message.
type QueuedMailPayload ¶
QueuedMailPayload holds the data for a background email task.
type ResendMailer ¶
type ResendMailer struct {
// contains filtered or unexported fields
}
ResendMailer implements the Mailer interface using Resend.com.
func NewResendMailer ¶
func NewResendMailer(cfg config.MailConfig, emitter *event.Emitter) *ResendMailer
NewResendMailer creates a new ResendMailer.
type SMTPMailer ¶
type SMTPMailer struct {
// contains filtered or unexported fields
}
SMTPMailer implements the Mailer interface using SMTP.
func NewSMTPMailer ¶
func NewSMTPMailer(cfg config.MailConfig, emitter *event.Emitter) *SMTPMailer
NewSMTPMailer creates a new SMTPMailer.
type TemplateMailer ¶
type TemplateMailer struct {
// contains filtered or unexported fields
}
TemplateMailer wraps a base Mailer and adds HTML template rendering for Mailable.
func NewTemplateMailer ¶
func NewTemplateMailer(base Mailer, opts ...TemplateMailerOption) *TemplateMailer
NewTemplateMailer creates a TemplateMailer that renders Mailable into HTML before handing off to the underlying Mailer.
func (*TemplateMailer) QueueMailable ¶
func (tm *TemplateMailer) QueueMailable(m Mailable) (*queue.GenericJob[QueuedMailPayload], error)
QueueMailable renders the mailable and returns a background job to send it.
func (*TemplateMailer) Send ¶
func (tm *TemplateMailer) Send(ctx context.Context, msg *Message) error
Send implements mail.Mailer so TemplateMailer can be used anywhere Mailer is expected. It delegates raw (pre-built) messages directly to the underlying mailer.
func (*TemplateMailer) SendMailable ¶
func (tm *TemplateMailer) SendMailable(m Mailable) (*Message, error)
SendMailable renders the Mailable's template (with optional layout wrapping) and then returns the resulting message.
type TemplateMailerOption ¶
type TemplateMailerOption func(*TemplateMailer)
TemplateMailerOption configures a TemplateMailer.
func WithDefaultFrom ¶
func WithDefaultFrom(from string) TemplateMailerOption
WithDefaultFrom sets the default sender address.
func WithDefaultLayout ¶
func WithDefaultLayout(layout string) TemplateMailerOption
WithDefaultLayout sets the default layout template for all emails. Set to "" to disable layout wrapping by default.
func WithMailExtension ¶
func WithMailExtension(ext string) TemplateMailerOption
WithMailExtension sets the template file extension (default: ".html").
func WithMailFS ¶
func WithMailFS(filesystem fs.FS) TemplateMailerOption
WithMailFS sets the filesystem for email templates.
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer handles HTML email templates.
func NewTemplateRenderer ¶
func NewTemplateRenderer(fileSystem fs.FS) *TemplateRenderer
NewTemplateRenderer creates a new TemplateRenderer.