Skip to main content

Crate gatekpr_email

Crate gatekpr_email 

Source
Expand description

Email Notification Service for Gatekpr SaaS

This crate provides a complete email notification system with:

  • SMTP email sending via lettre
  • Responsive HTML templates via mrml (Rust MJML)
  • Variable substitution via handlebars
  • Type-safe email job definitions
  • Background job queue via apalis (optional)

§Architecture

§Synchronous Mode

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│ EmailClient │────▶│  Template   │────▶│   lettre    │
│  (facade)   │     │  Renderer   │     │   (SMTP)    │
└─────────────┘     └─────────────┘     └─────────────┘

§Queue Mode (with queue feature)

┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  Producer   │────▶│    Redis    │────▶│   Worker    │────▶│   SMTP      │
│  (enqueue)  │     │   (queue)   │     │  (process)  │     │  (send)     │
└─────────────┘     └─────────────┘     └─────────────┘     └─────────────┘

§Example (Synchronous)

use gatekpr_email::{EmailClient, EmailConfig, templates::WelcomeEmail};

let config = EmailConfig::from_env()?;
let client = EmailClient::new(config)?;

let email = WelcomeEmail {
    to: "user@example.com".to_string(),
    name: "John".to_string(),
    verify_url: "https://example.com/verify/token123".to_string(),
};

client.send(email).await?;

§Example (Queue Mode)

use gatekpr_email::queue::{EmailJobProducer, EmailWorker};

// Producer side (enqueue emails)
let producer = EmailJobProducer::connect("redis://localhost:6379").await?;
producer.send_welcome("user@example.com", "John", "https://verify.url").await?;

// Worker side (process emails)
let worker = EmailWorker::new(producer.storage(), email_client, config).await?;
worker.run().await?;

Re-exports§

pub use client::EmailClient;
pub use config::EmailConfig;
pub use error::EmailError;
pub use error::Result;
pub use templates::EmailTemplate;
pub use templates::TemplateRenderer;

Modules§

client
Email client for sending emails via SMTP
config
Email configuration management
error
Error types for email operations
templates
Email template management and rendering