email

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg *config.EmailConfig, provider Provider) error

ValidateConfig validates email configuration for a specific provider

Types

type Config

type Config struct {
	EmailConfig *config.EmailConfig
	FrontendURL string
	Logger      Logger
}

Config holds email sender configuration

type EmailBuilder

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

EmailBuilder helps build specific types of emails This is where business logic lives - not in the email clients

func NewEmailBuilder

func NewEmailBuilder(frontendURL, defaultFrom string) (*EmailBuilder, error)

NewEmailBuilder creates a new email builder

func (*EmailBuilder) BuildCustomEmail

func (b *EmailBuilder) BuildCustomEmail(to, subject, htmlBody string) (*EmailMessage, error)

BuildCustomEmail builds a custom email with provided subject and body

func (*EmailBuilder) BuildInvitationEmail

func (b *EmailBuilder) BuildInvitationEmail(to, inviterName, code, role string) (*EmailMessage, error)

BuildInvitationEmail builds an invitation email message

func (*EmailBuilder) BuildInvitationWithOrgEmail

func (b *EmailBuilder) BuildInvitationWithOrgEmail(to, inviterName, code, role, orgName string) (*EmailMessage, error)

BuildInvitationWithOrgEmail builds an invitation email with organization info

func (*EmailBuilder) BuildShareInviteEmail

func (b *EmailBuilder) BuildShareInviteEmail(to, inviterName, itemName string) (*EmailMessage, error)

BuildShareInviteEmail builds a share invite email for non-registered recipients

func (*EmailBuilder) BuildShareNotificationEmail

func (b *EmailBuilder) BuildShareNotificationEmail(to, inviterName, itemName string) (*EmailMessage, error)

BuildShareNotificationEmail builds a share notification email for existing users

func (*EmailBuilder) BuildVerificationEmail

func (b *EmailBuilder) BuildVerificationEmail(to, name, code string) (*EmailMessage, error)

BuildVerificationEmail builds a verification email message

type EmailMessage

type EmailMessage struct {
	To      string   // Primary recipient
	From    string   // Sender email address
	Subject string   // Email subject
	Body    string   // HTML body content
	CC      []string // Carbon copy recipients (optional)
	BCC     []string // Blind carbon copy recipients (optional)
}

EmailMessage represents an email to be sent

type Logger

type Logger interface {
	Debug(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Warn(msg string, keysAndValues ...interface{})
	Error(msg string, keysAndValues ...interface{})
}

Logger interface for logging

type Provider

type Provider string

Provider represents the email sending provider

const (
	ProviderSMTP     Provider = "smtp"
	ProviderAWSSES   Provider = "aws-ses"
	ProviderGmailAPI Provider = "gmail-api"
)

type Sender

type Sender interface {
	// Send sends an email message
	Send(ctx context.Context, message *EmailMessage) error

	// Provider returns the current provider being used
	Provider() Provider

	// Close closes any open connections and cleans up resources
	Close() error
}

Sender defines the interface for sending emails Email clients should only know how to send, not what to send

func NewSender

func NewSender(cfg Config) (Sender, error)

NewSender creates a new email sender based on configuration It automatically detects the provider based on available credentials Priority: Gmail API > AWS SES > SMTP

type TemplateData

type TemplateData struct {
	Name             string
	Code             string
	ExpiryTime       string
	Year             int
	VerificationURL  string
	InviterName      string
	Role             string
	InvitationURL    string
	OrganizationName string // For org invitations
	ShareItemName    string
	ShareInviterName string
	ShareSignupURL   string
	ShareSignInURL   string
	ShareRecipient   string
}

TemplateData holds data for email templates

func BuildInvitationEmail

func BuildInvitationEmail(frontendURL, to, inviterName, code, role string) (*TemplateData, error)

BuildInvitationEmail builds an invitation email

func BuildInvitationEmailWithOrg

func BuildInvitationEmailWithOrg(frontendURL, to, inviterName, code, role, orgName string) (*TemplateData, error)

BuildInvitationEmailWithOrg builds an invitation email with organization info

func BuildShareInviteEmail

func BuildShareInviteEmail(frontendURL, to, inviterName, itemName string) (*TemplateData, error)

BuildShareInviteEmail builds a personal share invite email (for non-registered recipients)

func BuildShareNoticeEmail

func BuildShareNoticeEmail(frontendURL, to, inviterName, itemName string) (*TemplateData, error)

BuildShareNoticeEmail builds a share notification email (for registered recipients)

func BuildVerificationEmail

func BuildVerificationEmail(frontendURL, to, name, code string) (*TemplateData, error)

BuildVerificationEmail builds a verification email with the given parameters

type TemplateManager

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

TemplateManager handles email template rendering

func NewTemplateManager

func NewTemplateManager() (*TemplateManager, error)

NewTemplateManager creates a new template manager

func (*TemplateManager) Render

func (tm *TemplateManager) Render(templateType TemplateType, data interface{}) (string, error)

Render renders an email template with the given data

type TemplateType

type TemplateType string

TemplateType represents different email templates

const (
	TemplateVerification TemplateType = "verification"
	TemplateInvitation   TemplateType = "invitation"
	TemplateShareInvite  TemplateType = "share-invite"
	TemplateShareNotice  TemplateType = "share-notice"
)

Jump to

Keyboard shortcuts

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