use serde::{Deserialize, Serialize}; /// 邮件内容类型 #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum ContentType { /// 纯文本 Text, /// HTML格式 Html, } /// 邮件优先级 #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum Priority { Low, Normal, High, } /// 邮件请求 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EmailRequest { /// 收件人邮箱 pub to: String, /// 收件人姓名(可选) pub to_name: Option, /// 邮件主题 pub subject: String, /// 邮件正文 pub body: String, /// 内容类型 pub content_type: ContentType, /// 优先级 pub priority: Option, /// 抄送列表(可选) pub cc: Option>, /// 密送列表(可选) pub bcc: Option>, } impl Default for EmailRequest { fn default() -> Self { Self { to: String::new(), to_name: None, subject: String::new(), body: String::new(), content_type: ContentType::Text, priority: Some(Priority::Normal), cc: None, bcc: None, } } } impl EmailRequest { /// 创建简单的文本邮件请求 pub fn simple(to: &str, subject: &str, body: &str) -> Self { Self { to: to.to_string(), to_name: None, subject: subject.to_string(), body: body.to_string(), content_type: ContentType::Text, priority: Some(Priority::Normal), cc: None, bcc: None, } } /// 创建HTML邮件请求 pub fn html(to: &str, subject: &str, html_body: &str) -> Self { Self { to: to.to_string(), to_name: None, subject: subject.to_string(), body: html_body.to_string(), content_type: ContentType::Html, priority: Some(Priority::Normal), cc: None, bcc: None, } } } /// 邮件发送结果 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EmailResult { /// 是否成功 pub success: bool, /// 收件人 pub recipient: String, /// 错误信息(如果有) pub error: Option, /// 消息ID(SMTP服务器返回) pub message_id: Option, } impl EmailResult { /// 创建成功结果 pub fn success(recipient: &str, message_id: Option<&str>) -> Self { Self { success: true, recipient: recipient.to_string(), error: None, message_id: message_id.map(|s| s.to_string()), } } /// 创建失败结果 pub fn failure(recipient: &str, error: &str) -> Self { Self { success: false, recipient: recipient.to_string(), error: Some(error.to_string()), message_id: None, } } }