Skip to main content

backbone_email/
lib.rs

1//! Backbone Framework Email Module
2//!
3//! Provides email functionality with SMTP support.
4//!
5//! ## Features
6//!
7//! - **SMTP Provider**: Direct SMTP server support
8//! - **Template Support**: Handlebars template rendering
9//! - **Async/Await**: Full async support with tokio
10//! - **Attachments**: File attachment support
11//! - **Bulk Email**: Send to multiple recipients
12//! - **Email Tracking**: Track delivery status
13//!
14//! ## Quick Start
15//!
16//! ```ignore
17//! use backbone_email::{EmailService, SmtpProvider, EmailMessage};
18//!
19//! // SMTP email service
20//! let email_service = SmtpProvider::new("smtp.gmail.com", 587)
21//!     .with_credentials("user@example.com", "password")
22//!     .build();
23//!
24//! // Send email
25//! let message = EmailMessage::builder()
26//!     .from("sender@example.com")
27//!     .to("recipient@example.com")
28//!     .subject("Hello")
29//!     .text("This is a test email")
30//!     .build();
31//!
32//! let result = email_service.send(message).await?;
33//! ```
34
35pub mod smtp;
36pub mod traits;
37pub mod types;
38
39pub use traits::*;
40pub use types::*;
41pub use smtp::*;
42
43/// Email module version
44pub const VERSION: &str = env!("CARGO_PKG_VERSION");
45
46/// Default email port for SMTP
47pub const DEFAULT_SMTP_PORT: u16 = 587;
48
49/// Maximum attachment size (25MB)
50pub const MAX_ATTACHMENT_SIZE: usize = 25 * 1024 * 1024;
51
52/// Email error types
53#[derive(thiserror::Error, Debug)]
54pub enum EmailError {
55    #[error("SMTP connection error: {0}")]
56    SmtpConnection(String),
57
58    #[error("SMTP authentication error: {0}")]
59    SmtpAuth(String),
60
61    #[error("SMTP send error: {0}")]
62    SmtpSend(String),
63
64    #[error("Template rendering error: {0}")]
65    TemplateError(String),
66
67    #[error("Invalid email address: {0}")]
68    InvalidEmail(String),
69
70    #[error("Attachment error: {0}")]
71    AttachmentError(String),
72
73    #[error("Configuration error: {0}")]
74    ConfigError(String),
75
76    #[error("Network error: {0}")]
77    NetworkError(String),
78
79    #[error("Email error: {0}")]
80    Other(String),
81}
82
83/// Result type for email operations
84pub type EmailResult<T> = Result<T, EmailError>;
85
86/// Email service configuration
87#[derive(Debug, Clone)]
88pub struct EmailConfig {
89    /// SMTP configuration (optional)
90    pub smtp: Option<SmtpConfig>,
91
92    /// Default sender email
93    pub default_sender: Option<String>,
94
95    /// Default reply-to email
96    pub default_reply_to: Option<String>,
97
98    /// Enable email tracking
99    pub enable_tracking: bool,
100
101    /// Maximum retry attempts
102    pub max_retries: u32,
103
104    /// Retry delay in seconds
105    pub retry_delay: u64,
106}
107
108impl Default for EmailConfig {
109    fn default() -> Self {
110        Self {
111            smtp: None,
112            default_sender: None,
113            default_reply_to: None,
114            enable_tracking: false,
115            max_retries: 3,
116            retry_delay: 5,
117        }
118    }
119}
120
121/// Email provider types
122#[derive(Debug, Clone)]
123pub enum EmailProvider {
124    Smtp,
125}
126
127impl EmailProvider {
128    /// Get provider name
129    pub fn name(&self) -> &'static str {
130        match self {
131            Self::Smtp => "smtp",
132        }
133    }
134}