Email queue for sending emails with configurable delays to avoid spam filters.
This GenServer maintains a queue of emails to be sent and processes them one at a time with a configurable delay between sends.
Features:
- Rate limiting: Configurable delay between emails
- Retry logic: Failed emails are retried up to N times
- Priority queue: Support for urgent emails
- Statistics: Track sent, failed, and queued emails
Configuration:
- config :voile, :email_queue_delay, 2000 # milliseconds between emails (default: 2 seconds)
- config :voile, :email_queue_max_retries, 3 # maximum retry attempts
Summary
Functions
Returns a specification to start this module under a supervisor.
Clear the queue (useful for testing or maintenance).
Queue an email to be sent.
Pause email processing.
Resume email processing.
Get current queue statistics.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Clear the queue (useful for testing or maintenance).
Queue an email to be sent.
Parameters
- email_fn: A function that sends the email and returns {:ok, result} or {:error, reason}
- opts: Options
- :priority - :high, :normal, or :low (default: :normal)
- :metadata - Map of metadata for logging
Examples
EmailQueue.enqueue(fn ->
LoanReminderEmail.send_reminder_email(member, transactions, 3)
end, metadata: %{member_id: 123, type: :reminder})
Pause email processing.
Resume email processing.
Get current queue statistics.