email_sender 0.1.4

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

SMTP_SERVER=smtp.qq.com # QQ 邮箱的 SMTP 服务器地址 SMTP_PORT=465 # 端口号 465(SSL/TLS 加密连接) SMTP_USERNAME=your_email@qq.com # 发件人邮箱地址 SMTP_PASSWORD=your_smtp_token # SMTP 授权码(不是邮箱登录密码) EMAIL_FROM=your_email@qq.com # 发件人邮箱 EMAIL_TO=recipient@example.com # 收件人邮箱 EMAIL_SUBJECT=测试邮件 # 邮件主题 EMAIL_BODY=这是一封测试邮件内容 # 邮件正文

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);
    }
}