Documentation
¶
Index ¶
- func HasMissingFields(r parser.Recipient) bool
- func PrepareEmailTasks(recipients []parser.Recipient, templatePath, plainText, subjectTpl string, ...) ([]email.Task, error)
- func Run(args CLIArgs) error
- func SendSingleEmail(args CLIArgs, cfg config.SMTPConfig) error
- func StreamEmailTasks(ctx context.Context, recipients []parser.Recipient, ...) (<-chan email.Task, <-chan error)
- type CLIArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasMissingFields ¶
HasMissingFields returns true if the recipient email is empty. Other data fields may be optional depending on the template, so only the email field is required.
func PrepareEmailTasks ¶
func PrepareEmailTasks(recipients []parser.Recipient, templatePath, plainText, subjectTpl string, attachments []string, ccList []string, bccList []string) ([]email.Task, error)
PrepareEmailTasks renders the subject and body templates for each recipient and returns a list of email.Task objects ready for sending.
plainText is optional plain-text content (inline string or file path resolved by the caller). When both templatePath (HTML) and plainText are provided, the task carries both bodies so the sender can build a multipart/alternative message.
func Run ¶
Run is the main orchestration function. It controls the full Mailgrid lifecycle: 1. Load config 2. Parse CSV or Google Sheet 3. Apply optional filter 4. Preview or send emails
func SendSingleEmail ¶ added in v1.0.0
func SendSingleEmail(args CLIArgs, cfg config.SMTPConfig) error
SendSingleEmail handles one-off email sending using --to.
Accepted combinations:
- --template only: HTML email
- --text only: plain-text email
- --template + --text: multipart/alternative (HTML + plain text)
func StreamEmailTasks ¶ added in v1.1.0
func StreamEmailTasks(ctx context.Context, recipients []parser.Recipient, templatePath, plainText, subjectTpl string, attachments []string, ccList []string, bccList []string, skipN, bufSize int) (<-chan email.Task, <-chan error)
StreamEmailTasks renders subject and body templates lazily and writes the resulting tasks to the returned channel. The channel is closed when all recipients have been processed or ctx is cancelled.
Use this in place of PrepareEmailTasks when the recipient set is large enough that materializing all rendered bodies in RAM is undesirable; the channel-based dispatcher (email.StartDispatcherStream) consumes the same channel directly so render and send overlap.
skipN drops the first N renderable tasks before emitting any — used to resume from a saved offset. Each emitted task carries Index = N + position after the skip, matching the offset baseline so MarkComplete advances the tracker correctly. Recipients that fail to render (missing fields, template error) are logged, skipped, and never count toward skipN or Index.
Types ¶
type CLIArgs ¶
type CLIArgs struct {
EnvPath string // Path to an SMTP config JSON file
CSVPath string // Path to recipient CSV file
TemplatePath string // Path to HTML email template
Subject string // Subject line (supports templating with {{ .name }})
DryRun bool // If true, render but do not send emails
ShowPreview bool // If true, serve rendered HTML via localhost
PreviewPort int // Port to run the preview server on
Concurrency int // Number of parallel SMTP workers
RetryLimit int // Max retry attempts for failed sending
BatchSize int // Number of emails sent per SMTP batch
SheetURL string // Optional Google Sheet URL for CSV import
Filter string // Logical filter expression for recipients
Attachments []string // File paths to attach to every email
Cc string // Comma-separated emails or file path for CC
Bcc string // Comma-separated emails or file path for BCC
To string // Email address for one-off sending
Text string // Inline plain-text body or path to a text file
WebhookURL string // HTTP URL to send completion notification
WebhookSecret string // Optional HMAC-SHA256 secret for webhook signature
// Monitoring
Monitor bool // Enable real-time monitoring dashboard
MonitorPort int // Port for monitoring dashboard (includes metrics)
// Scheduling
ScheduleAt string // RFC3339 timestamp
Interval string // Go duration, e.g. "1h", "30m"
Cron string // Cron expression (5-field)
JobRetries int // Scheduler retry attempts
// Job management
ListJobs bool // List scheduled jobs
CancelJobID string // Cancel job by ID
SchedulerRun bool // Run dispatcher in foreground
// Version
ShowVersion bool // Show version information and exit
// Help
ShowHelp bool // Show help message
// Offset tracking
Resume bool // Resume from last saved offset
ResetOffset bool // Clear offset file and start from beginning
DBPath string // Path to the BoltDB database file
// Timeouts
SMTPTimeout int // SMTP dial timeout in seconds (default 10)
MonitorClientTimeout int // Idle SSE client timeout in seconds (default 300)
// Logging
LogLevel string // Log level: debug, info, warn, error (default "info")
LogFormat string // Log format: text, json (default "text")
}
CLIArgs holds all configurable options passed via the command line.
func ParseFlags ¶
func ParseFlags() CLIArgs