=============== LIBRARY RULES =============== From library maintainers: - Add to Cargo.toml: euromail = "0.2" - Initialize: let client = EuroMail::new(std::env::var("EUROMAIL_API_KEY").unwrap()) - send_email() is async and takes &SendEmailParams — use ..Default::default() for optional fields - Returns SendEmailResponse with .id and .status where status is 'queued' - Use template_alias field (String) not template_id when sending with a template - dns_records is HashMap keyed by purpose (dkim, return_path) - verify_domain() returns DomainVerificationResult with .checks HashMap - The from field must use the apex domain, not the sending subdomain (em.yourdomain.com) - Agent mailbox: get_next_mailbox_message() → process → ack_mailbox_message() with lease_token ### Quick Start: Send an Email with Euromail SDK Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Initialize the EuroMail client with your API key and send a basic email. Ensure you replace 'em_live_your_api_key_here' with your actual API key. This example requires the tokio runtime. ```rust use euromail::{EuroMail, SendEmailParams}; #[tokio::main] async fn main() -> Result<(), euromail::EuroMailError> { let client = EuroMail::new("em_live_your_api_key_here"); let response = client.send_email( &SendEmailParams::new("sender@yourdomain.com", "recipient@example.com") .subject("Hello from EuroMail") .html_body("

Welcome!

"), ).await?; println!("Email queued: {}", response.id); Ok(()) } ``` -------------------------------- ### Get Email Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Retrieve details of a specific email by its ID. ```APIDOC ## Get Email ### Description Retrieve details of a specific email by its ID. ### Method ```rust client.get_email() ``` ### Parameters #### Path Parameters - **email_id** (string) - Required - The unique identifier of the email to retrieve. ### Response #### Success Response (200) - **email** (Email) - The details of the requested email. ``` -------------------------------- ### Initialize EuroMail Client Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Create a new instance of the EuroMail client using your API key. Replace 'em_live_...' with your actual API key. ```rust let client = EuroMail::new("em_live_..."); ``` -------------------------------- ### Welcome Email Configuration Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Configure an automatic welcome email that is sent when a contact is added to a list. ```APIDOC ### Configure Welcome Email Configures the welcome email for a contact list. - **Method**: PUT (assumed, based on `configure_` prefix) - **Endpoint**: `/contact-lists/{list_id}/welcome-email` (assumed) - **Parameters**: - **list_id** (string) - Required - The ID of the contact list. - **Request Body**: `ConfigureWelcomeEmailParams` - **enable** (boolean) - Required - Whether to enable the welcome email. - **subject** (string) - Optional - The subject line of the welcome email. - **html_body** (string) - Optional - The HTML content of the welcome email. - **template_id** (string) - Optional - The ID of a template to use for the email (mutually exclusive with `html_body`). - **delay_seconds** (integer) - Optional - The delay in seconds before sending the email (0 to MAX_WELCOME_DELAY_SECONDS). ### Get Welcome Email Configuration Retrieves the current welcome email configuration for a contact list. - **Method**: GET (assumed, based on `get_` prefix) - **Endpoint**: `/contact-lists/{list_id}/welcome-email` (assumed) - **Parameters**: - **list_id** (string) - Required - The ID of the contact list. ``` -------------------------------- ### Agent Mailboxes - Create and Lease Messages Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Demonstrates how to create an agent mailbox and then continuously wait for and process incoming messages using a lease/ack/nack model. ```APIDOC ## Agent Mailboxes Agent mailboxes provide persistent email addresses for AI agents with at-least-once message delivery via a lease/ack/nack model. The SDK wraps the full flow natively: ```rust use euromail::{CreateMailboxParams, EuroMail}; # async fn run() -> Result<(), euromail::EuroMailError> { let client = EuroMail::from_env(); // Create a mailbox (omit local_part/domain_id for a server-generated address) let mailbox = client.create_mailbox(&CreateMailboxParams { display_name: Some("Support Agent".into()), ..Default::default() }).await?; loop { // Long-poll for the next message. Returns Ok(None) on HTTP 408 // (no message available within the timeout window). let Some(leased) = client.wait_for_next_message(&mailbox.id, Some(30)).await? else { continue; }; match handle(&leased.data).await { Ok(_) => { // Ack when done — message will not be redelivered client.ack_message(&mailbox.id, &leased.data.id, &leased.lease_token).await?; } Err(_) => { // Nack returns the message to the queue for retry client.nack_message(&mailbox.id, &leased.data.id, &leased.lease_token).await?; } } } # } # async fn handle(_msg: &euromail::MailboxMessage) -> Result<(), euromail::EuroMailError> { Ok(()) } ``` Other methods: `list_mailboxes`, `get_mailbox`, `delete_mailbox`, `list_mailbox_messages`, `delete_mailbox_message`. ``` -------------------------------- ### Configure Welcome Email Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Configures an automatic welcome email for new contacts. This can be enabled with a subject and HTML body. Note that `template_id` and inline bodies are mutually exclusive. `delay_seconds` can be set up to 7 days. ```rust use euromail::ConfigureWelcomeEmailParams; client.configure_welcome_email( &list.id, &ConfigureWelcomeEmailParams::new() .enable() .subject("Welcome to the list!") .html_body("

Thanks for subscribing.

"), ).await?; let config = client.get_welcome_email(&list.id).await?; assert!(config.enabled); ``` -------------------------------- ### Create, Update, and Test Webhooks Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Demonstrates how to create, update, test, list, and delete webhooks using the Euromail Rust SDK. Ensure the webhook URL is accessible and correctly configured to receive events. ```rust use euromail::{CreateWebhookParams, UpdateWebhookParams}; let webhook = client.create_webhook(&CreateWebhookParams { url: "https://yourdomain.com/webhooks/euromail".into(), events: vec!["delivered".into(), "bounced".into(), "complained".into()], }).await?; // Update client.update_webhook(&webhook.id, &UpdateWebhookParams { url: "https://yourdomain.com/webhooks/v2".into(), events: vec!["delivered".into(), "bounced".into()], is_active: true, }).await?; // Send test event let test = client.test_webhook(&webhook.id).await?; // List and delete let webhooks = client.list_webhooks(None).await?; client.delete_webhook(&webhook.id).await?; ``` -------------------------------- ### Create and Manage Contact Lists Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Covers the creation of contact lists, adding single contacts, bulk adding contacts, listing contacts, removing contacts, and deleting lists. Double opt-in can be enabled during list creation. ```rust use euromail::{CreateContactListParams, AddContactParams, BulkAddContactsParams}; let list = client.create_contact_list(&CreateContactListParams { name: "Newsletter".into(), description: Some("Monthly product updates".into()), double_opt_in: Some(true), }).await?; // Add a single contact let contact = client.add_contact(&list.id, &AddContactParams { email: "user@example.com".into(), metadata: None, }).await?; // Bulk add let result = client.bulk_add_contacts(&list.id, &BulkAddContactsParams { contacts: vec![ AddContactParams { email: "a@example.com".into(), metadata: None }, AddContactParams { email: "b@example.com".into(), metadata: None }, ], }).await?; println!("Inserted: {} of {}", result.inserted, result.total_requested); // List contacts let contacts = client.list_contacts(&list.id, None).await?; // Remove contact and delete list client.remove_contact(&list.id, "user@example.com").await?; client.delete_contact_list(&list.id).await?; ``` -------------------------------- ### Create and Manage Inbound Routes Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Demonstrates how to create, list, and delete inbound email routes. Routes can direct incoming emails to a specified webhook URL based on domain and pattern matching. ```rust use euromail::CreateInboundRouteParams; // Route incoming email to a webhook let route = client.create_inbound_route(&CreateInboundRouteParams { domain_id: "domain-uuid".into(), pattern: "support@".into(), match_type: "prefix".into(), priority: Some(10), webhook_url: Some("https://yourdomain.com/inbound/support".into()), }).await?; // List and delete let routes = client.list_inbound_routes(None).await?; client.delete_inbound_route(&route.id).await?; ``` -------------------------------- ### Create, Update, List, and Delete Email Templates Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Manage email templates by creating, updating, listing, and deleting them. Templates can use placeholders like {{name}} which can be populated with data during sending. ```rust use euromail::{CreateTemplateParams, UpdateTemplateParams}; let template = client.create_template(&CreateTemplateParams { alias: "welcome".into(), name: "Welcome Email".into(), subject: "Welcome, {{name}}!".into(), html_body: Some("

Welcome, {{name}}!

".into()), text_body: None, }).await?; // Update client.update_template(&template.id, &UpdateTemplateParams { subject: Some("Welcome to {{company}}, {{name}}!".into()), ..Default::default() }).await?; // List and delete let templates = client.list_templates(None).await?; client.delete_template(&template.id).await?; ``` -------------------------------- ### Manage Agent Mailboxes in Rust Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Shows how to create an agent mailbox, continuously wait for new messages, and acknowledge or negatively acknowledge them. This pattern ensures at-least-once message delivery for AI agents. ```rust use euromail::{CreateMailboxParams, EuroMail}; # async fn run() -> Result<(), euromail::EuroMailError> { let client = EuroMail::from_env(); // Create a mailbox (omit local_part/domain_id for a server-generated address) let mailbox = client.create_mailbox(&CreateMailboxParams { display_name: Some("Support Agent".into()), ..Default::default() }).await?; loop { // Long-poll for the next message. Returns Ok(None) on HTTP 408 // (no message available within the timeout window). let Some(leased) = client.wait_for_next_message(&mailbox.id, Some(30)).await? else { continue; }; match handle(&leased.data).await { Ok(_) => { // Ack when done — message will not be redelivered client.ack_message(&mailbox.id, &leased.data.id, &leased.lease_token).await?; } Err(_) => { // Nack returns the message to the queue for retry client.nack_message(&mailbox.id, &leased.data.id, &leased.lease_token).await?; } } } # } # async fn handle(_msg: &euromail::MailboxMessage) -> Result<(), euromail::EuroMailError> { Ok(()) } ``` -------------------------------- ### Manage Account Information Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Covers retrieving account details such as plan, email usage, and quota. Also includes options for exporting account data for GDPR compliance and permanently deleting the account. ```rust let account = client.get_account().await?; println!("Plan: {}, Used: {}/{}", account.plan, account.emails_sent_this_month, account.monthly_quota); // Export account data (GDPR) let export = client.export_account().await?; // Delete account permanently client.delete_account().await?; ``` -------------------------------- ### Create Template Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Create a new email template for use with the SDK. ```APIDOC ## Create Template ### Description Create a new email template for use with the SDK. ### Method ```rust client.create_template() ``` ### Parameters #### Request Body - **params** (CreateTemplateParams) - Required - Parameters for creating the template. - **alias** (string) - Required - A unique alias for the template. - **name** (string) - Required - The display name of the template. - **subject** (string) - Required - The subject line of the email, can include template variables. - **html_body** (Option) - Optional - The HTML content of the email body. - **text_body** (Option) - Optional - The plain text content of the email body. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created template. - **alias** (string) - The alias of the template. - **name** (string) - The name of the template. - **subject** (string) - The subject line of the template. - **html_body** (Option) - The HTML content of the template. - **text_body** (Option) - The plain text content of the template. ``` -------------------------------- ### List and Process Audit Logs Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Fetches audit logs to track actions performed within the account. Each log entry includes creation timestamp, action, and resource type. ```rust let logs = client.list_audit_logs(None).await?; for log in &logs.data { println!("{}: {} on {}", log.created_at, log.action, log.resource_type); } ``` -------------------------------- ### Send Email with Detailed Parameters Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Send an email with custom subject, HTML and plain text bodies, reply-to address, tags, and metadata. This demonstrates the flexibility of SendEmailParams. ```rust use euromail::SendEmailParams; let response = client.send_email( &SendEmailParams::new("noreply@yourdomain.com", "user@example.com") .subject("Order Confirmation") .html_body("

Thanks for your order!

") .text_body("Thanks for your order!") .reply_to("support@yourdomain.com") .tag("order") .tag("confirmation") .metadatum("order_id", "12345"), ).await?; ``` -------------------------------- ### Register and Verify a Sending Domain Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Register a new sending domain with Euromail and trigger DNS verification. The response includes necessary DNS records for configuration. ```rust // Register a sending domain let domain = client.add_domain("mail.yourdomain.com").await?; println!("Configure DNS records: {:?}", domain.dns_records); // Trigger verification let verification = client.verify_domain(&domain.id).await?; if verification.fully_verified { println!("Domain verified!"); } // List all domains let domains = client.list_domains(None).await?; // Remove a domain client.delete_domain(&domain.id).await?; ``` -------------------------------- ### Manage Suppressions Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Shows how to add, list, and delete email addresses from the suppression list. Suppressed emails will not be delivered. ```rust client.add_suppression("bounced@example.com", Some("hard_bounce")).await?; let suppressions = client.list_suppressions(None).await?; client.delete_suppression("bounced@example.com").await?; ``` -------------------------------- ### Add Domain Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Register a new sending domain with EuroMail. ```APIDOC ## Add Domain ### Description Register a new sending domain with EuroMail. ### Method ```rust client.add_domain() ``` ### Parameters #### Request Body - **domain_name** (string) - Required - The domain name to register (e.g., "mail.yourdomain.com"). ### Response #### Success Response (200) - **id** (string) - The unique identifier for the registered domain. - **dns_records** (Vec) - DNS records that need to be configured for domain verification. ``` -------------------------------- ### Add Euromail and Tokio to Dependencies Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Add the euromail and tokio crates to your Cargo.toml file to use the SDK. Tokio is required for asynchronous operations. ```toml euromail = "0.3" tokio = { version = "1", features = ["full"] } ``` -------------------------------- ### Schedule Email for Future Delivery Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Schedule an email to be sent at a specific date and time in the future. The 'send_at' parameter accepts an ISO 8601 formatted string. ```rust let response = client.send_email( &SendEmailParams::new("noreply@yourdomain.com", "user@example.com") .subject("Reminder") .text_body("Your trial ends tomorrow.") .send_at("2026-05-01T09:00:00Z"), ).await?; assert_eq!(response.status, "scheduled"); // response.scheduled_at echoes back the release time. ``` -------------------------------- ### Handle EuroMail Errors in Rust Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Demonstrates how to match against various `EuroMailError` variants to handle different types of errors during email sending. Includes specific handling for authentication, validation, rate limiting, not found, API, and HTTP errors. ```rust use euromail::EuroMailError; match client.send_email(¶ms).await { Ok(response) => println!("Sent: {}", response.id), Err(EuroMailError::Authentication(msg)) => { eprintln!("Invalid API key: {msg}"); } Err(EuroMailError::Validation { code, message }) => { eprintln!("Validation error [{code}]: {message}"); } Err(EuroMailError::RateLimit { retry_after, message }) => { eprintln!("Rate limited: {message}"); if let Some(secs) = retry_after { tokio::time::sleep(std::time::Duration::from_secs(secs)).await; } } Err(EuroMailError::NotFound(msg)) => { eprintln!("Not found: {msg}"); } Err(EuroMailError::Api { status, code, message }) => { eprintln!("API error [{status}] {code}: {message}"); } Err(EuroMailError::Http(e)) => { eprintln!("Network error: {e}"); } } ``` -------------------------------- ### Send Email Using a Template Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Send an email using a pre-defined template. Provide the template alias and any necessary data as a JSON object to populate the template variables. ```rust use serde_json::json; let response = client.send_email( &SendEmailParams::new("noreply@yourdomain.com", "user@example.com") .template_alias("welcome-email") .template_data(json!({ "name": "John", "activation_url": "https://example.com/activate/abc123" })), ).await?; ``` -------------------------------- ### Retrieve Analytics Data Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Shows how to fetch various analytics data, including overview, time series metrics, and per-domain breakdowns. Data can be queried for specific periods and exported as CSV. ```rust use euromail::{AnalyticsQuery, TimeseriesQuery, DomainAnalyticsQuery}; // Overview for the last 30 days let overview = client.get_analytics_overview(Some(&AnalyticsQuery { period: Some("30d".into()), from: None, to: None, })).await?; // Time series let timeseries = client.get_analytics_timeseries(Some(&TimeseriesQuery { period: Some("7d".into()), from: None, to: None, metrics: Some("sent,delivered,bounced".into()), })).await?; // Per-domain breakdown let domains = client.get_analytics_domains(Some(&DomainAnalyticsQuery { period: Some("30d".into()), from: None, to: None, limit: Some(10), })).await?; // Export as CSV let csv = client.export_analytics_csv(None).await?; ``` -------------------------------- ### Verify Domain Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Trigger the verification process for a registered domain. ```APIDOC ## Verify Domain ### Description Trigger the verification process for a registered domain. ### Method ```rust client.verify_domain() ``` ### Parameters #### Path Parameters - **domain_id** (string) - Required - The ID of the domain to verify. ### Response #### Success Response (200) - **fully_verified** (bool) - Indicates if the domain is fully verified. - **verification_status** (string) - The current status of the domain verification. ``` -------------------------------- ### Inbound Routes Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Configure routes for directing incoming emails to specific webhooks based on patterns. ```APIDOC ## Inbound Routes ### Create Inbound Route Creates a new route for handling inbound emails. - **Method**: POST (assumed, based on `create_` prefix) - **Endpoint**: `/inbound-routes` (assumed) - **Request Body**: `CreateInboundRouteParams` - **domain_id** (string) - Required - The ID of the domain this route applies to. - **pattern** (string) - Required - The pattern to match for incoming email addresses (e.g., `support@`). - **match_type** (string) - Required - The type of pattern matching (e.g., `prefix`). - **webhook_url** (string) - Optional - The URL to send matched inbound emails to. - **priority** (integer) - Optional - The priority of this route. ### List Inbound Routes Retrieves a list of all configured inbound routes. - **Method**: GET (assumed, based on `list_` prefix) - **Endpoint**: `/inbound-routes` (assumed) - **Parameters**: - **query** (object) - Optional - Query parameters for filtering (e.g., `None`). ### Delete Inbound Route Deletes an inbound route. - **Method**: DELETE (assumed, based on `delete_` prefix) - **Endpoint**: `/inbound-routes/{id}` (assumed) - **Parameters**: - **id** (string) - Required - The ID of the inbound route to delete. ``` -------------------------------- ### List Templates Source: https://github.com/kalle-works/euromail-rust/blob/main/README.md Retrieve a list of all available email templates. ```APIDOC ## List Templates ### Description Retrieve a list of all available email templates. ### Method ```rust client.list_templates() ``` ### Response #### Success Response (200) - **templates** (Vec