email_sender 0.1.1

A simple email sender crate using lettre.
Documentation

email_sender

A simple Rust crate for sending emails using the lettre library.

Features

  • Send emails via SMTP
  • Configurable via environment variables or manually
  • Easy-to-use API

Installation

Add this to your Cargo.toml:

[dependencies]
email_sender = "0.1.0"
dotenv = "0.14.1"  # 如果需要从环境变量加载配置
thiserror = "1.0" 

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_send_email() {
        // 注意:实际发送邮件在测试中可能不可行,建议使用 Mock 或 Stub
        // 这里仅作为示例,实际应避免在测试中发送真实邮件
        let options = EmailOptions::new(
            "smtp.example.com".to_string(),
            587,
            "your_username".to_string(),
            "your_password".to_string(),
            "from@example.com".to_string(),
            "to@example.com".to_string(),
            "Test Subject".to_string(),
            "Test Body".to_string(),
        );

        // 由于需要真实的 SMTP 配置,这里可以 panic 或返回 Ok(())
        // 实际项目中应使用 Mock 测试
        assert!(true);
    }
}