2 个不稳定版本
0.2.0 | 2024年4月28日 |
---|---|
0.1.0 | 2024年4月26日 |
#106 在 邮件
每月45 次下载
45KB
564 行
Rust 邮件客户端
描述
此库为用户提供易于使用的 Rust 邮件客户端集合。您可以选择一个或多个邮件客户端,并使用此库轻松发送邮件。
功能
- 终端客户端用于本地开发
- 内存客户端用于测试用例
- 支持 TLS 和 STARTTLS 的 SMTP 客户端,本地支持
- Mailersend 配置
- 易于配置管理
安装
您可以使用以下方法将此库添加到项目中
$ cargo add email_clients
使用方法
为了快速入门,您可以执行以下操作:根据您想要支持的邮件客户端,您需要初始化以下电子邮件配置
async fn send_email() {
let email = EmailObject {
sender: "[email protected]",
to: vec![EmailAddress { name: "Mail".to_string(), email: "[email protected]".to_string() }],
subject: "subject".to_string(),
plain: "plain body".to_string(),
html: "<a>html body</a>".to_string(),
};
// Choose any of the config as below:
// 1. Terminal client (needs terminal feature, enabled by default)
let terminal_config: TerminalConfig = String::from("[email protected]").into(); // Terminal config
// 2. Smtp config (needs smtp feature)
let smtp_config = SmtpConfig::default().sender("[email protected]").relay("localhost");
// 3. Memory config (needs memory feature)
let (tx, rx) = mpsc::sync_channel(2);
let memory_config = String::from("[email protected]").into();
let email_configuration: EmailConfiguration = terminal_config.into(); // OR any of the other config
let client = get_email_client(email_configuration);
client.send_emails(email).await;
// For memory config, if you want to retain the receiver, you can do so using:
let memory_client = EmailClient::Memory(MemoryClient::with_tx(memory_config, tx));
}
测试
此处测试需要监听本地端口 2525 的开放邮件服务器。您可以使用以下方法实现
$ python -m smtpd -n -c DebuggingServer 127.0.0.1:2525
依赖项
~2–34MB
~524K SLoC