cli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasMissingFields

func HasMissingFields(r parser.Recipient) bool

HasMissingFields returns true if any field in recipient data is empty.

func PrepareEmailTasks

func PrepareEmailTasks(recipients []parser.Recipient, templatePath, 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.

func Run

func Run(args CLIArgs) error

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 along with either --template or --text (mutually exclusive).

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

	// Scheduling options (if any of these are set, we schedule instead of immediate sending)
	ScheduleAt string // RFC3339 timestamp
	Interval   string // Go duration, e.g. "1h", "30m"
	Cron       string // Cron expression (5-field)

	// Scheduler job-level retry/backoff (separate it from SMTP retries)
	JobRetries int
	JobBackoff string // duration

	// Job management
	ListJobs     bool
	CancelJobID  string
	SchedulerRun bool // Run dispatcher in foreground

	SchedulerDB string // Path to BoltDB file for persisted schedules
}

CLIArgs holds all configurable options passed via the command line. This struct is used throughout the Mailgrid CLI flow.

func ParseFlags

func ParseFlags() CLIArgs

ParseFlags reads command-line flags using spf13/pflag and returns a filled CLIArgs struct.

type Runner added in v1.0.0

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

Runner wires the EmailScheduler with concrete email-sending logic.

func NewRunner added in v1.0.0

func NewRunner(es *scheduler.EmailScheduler) *Runner

func (*Runner) EmailJobHandler added in v1.0.0

func (r *Runner) EmailJobHandler(job types.Job) error

EmailJobHandler executes a scheduled email job by decoding the payload and sending a single email.

func (*Runner) Run added in v1.0.0

func (r *Runner) Run(_ context.Context, a types.CLIArgs) error

Run schedules (or immediately executes) an email job based on the provided args.

Jump to

Keyboard shortcuts

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