Skip to content
This page was generated and translated with the assistance of AI. If you spot any inaccuracies, feel free to help improve it. Edit on GitHub

Quick Start ​

This guide takes you from zero to a working email setup in under 5 minutes. By the end, you will have PRX-Email configured with an account, inbox synced, and a test email sent.

Prerequisites

You need Rust 1.85+ installed. See the Installation Guide for build dependencies.

Step 1: Add PRX-Email to Your Project ​

Create a new Rust project or add to an existing one:

bash
cargo new my-email-app
cd my-email-app

Add the dependency to Cargo.toml:

toml
[dependencies]
prx_email = { git = "https://github.com/openprx/prx_email.git" }

Step 2: Initialize the Database ​

PRX-Email uses SQLite for all persistence. Open a store and run migrations:

rust
use prx_email::db::{EmailStore, EmailRepository, NewAccount};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open (or create) a SQLite database file
    let store = EmailStore::open("./email.db")?;

    // Run migrations to create all tables
    store.migrate()?;

    // Create a repository for database operations
    let repo = EmailRepository::new(&store);

    println!("Database initialized successfully.");
    Ok(())
}

The database is created with WAL mode, foreign keys enabled, and a 5-second busy timeout by default.

Step 3: Create an Email Account ​

rust
let now = std::time::SystemTime::now()
    .duration_since(std::time::UNIX_EPOCH)?
    .as_secs() as i64;

let account_id = repo.create_account(&NewAccount {
    email: "[email protected]".to_string(),
    display_name: Some("Your Name".to_string()),
    now_ts: now,
})?;

println!("Created account ID: {}", account_id);

Step 4: Configure Transport and Create the Plugin ​

rust
use prx_email::plugin::{
    EmailPlugin, EmailTransportConfig, ImapConfig, SmtpConfig,
    AuthConfig, AttachmentPolicy,
};

let config = EmailTransportConfig {
    imap: ImapConfig {
        host: "imap.example.com".to_string(),
        port: 993,
        user: "[email protected]".to_string(),
        auth: AuthConfig {
            password: Some("your-app-password".to_string()),
            oauth_token: None,
        },
    },
    smtp: SmtpConfig {
        host: "smtp.example.com".to_string(),
        port: 465,
        user: "[email protected]".to_string(),
        auth: AuthConfig {
            password: Some("your-app-password".to_string()),
            oauth_token: None,
        },
    },
    attachment_store: None,
    attachment_policy: AttachmentPolicy::default(),
};

let plugin = EmailPlugin::new_with_config(repo, config);

Step 5: Sync Your Inbox ​

rust
use prx_email::plugin::SyncRequest;

let result = plugin.sync(SyncRequest {
    account_id,
    folder: Some("INBOX".to_string()),
    cursor: None,
    now_ts: now,
    max_messages: 50,
});

match result {
    Ok(()) => println!("Inbox synced successfully."),
    Err(e) => eprintln!("Sync failed: {:?}", e),
}

Step 6: List Messages ​

rust
use prx_email::plugin::ListMessagesRequest;

let messages = plugin.list(ListMessagesRequest {
    account_id,
    limit: 10,
})?;

for msg in &messages {
    println!(
        "[{}] {} - {}",
        msg.message_id,
        msg.sender.as_deref().unwrap_or("unknown"),
        msg.subject.as_deref().unwrap_or("(no subject)"),
    );
}

Step 7: Send an Email ​

rust
use prx_email::plugin::SendEmailRequest;

let response = plugin.send(SendEmailRequest {
    account_id,
    to: "[email protected]".to_string(),
    subject: "Hello from PRX-Email".to_string(),
    body_text: "This is a test email sent via PRX-Email.".to_string(),
    now_ts: now,
    attachment: None,
    failure_mode: None,
});

if response.ok {
    let result = response.data.as_ref().unwrap();
    println!("Sent! Outbox ID: {}, Status: {}", result.outbox_id, result.status);
} else {
    let error = response.error.as_ref().unwrap();
    eprintln!("Send failed: {:?} - {}", error.code, error.message);
}

Step 8: Check Metrics ​

rust
let metrics = plugin.metrics_snapshot();
println!("Sync attempts: {}", metrics.sync_attempts);
println!("Sync success:  {}", metrics.sync_success);
println!("Sync failures: {}", metrics.sync_failures);
println!("Send failures: {}", metrics.send_failures);
println!("Retry count:   {}", metrics.retry_count);

What You Have Now ​

After completing these steps, your application has:

ComponentStatus
SQLite databaseInitialized with full schema
Email accountCreated and configured
IMAP syncConnected and fetching messages
SMTP outboxReady with atomic send pipeline
MetricsTracking sync and send operations

Common Provider Settings ​

ProviderIMAP HostIMAP PortSMTP HostSMTP PortAuth
Gmailimap.gmail.com993smtp.gmail.com465App password or OAuth
Outlookoutlook.office365.com993smtp.office365.com587OAuth (recommended)
Yahooimap.mail.yahoo.com993smtp.mail.yahoo.com465App password
Fastmailimap.fastmail.com993smtp.fastmail.com465App password

Gmail

Gmail requires either an App Password (with 2FA enabled) or OAuth 2.0. Regular passwords do not work with IMAP/SMTP. See the OAuth Guide for setup instructions.

Next Steps ​

Released under the Apache-2.0 License.