smtp_send
SMTP email sending library with DKIM signing, MX lookup, and automatic bounce handling.
Features
- DKIM Signing: RSA-SHA256 with RFC 6376 header protection (N+1 signing)
- MX Lookup: DNS-over-QUIC via
idoq - Concurrent Sending: Parallel delivery grouped by domain
- Failover: Tries multiple MX servers on failure
- Bounce Handling: Auto-generates RFC 5321 compliant rejection reports
- Loop Prevention: Checks
Receivedheader count (max 30) andAuto-Submitted/Return-Pathheaders - DKIM Cache: 600s TTL cache for signers
Usage
use Send;
use Mail;
async
API
Send
SendResult
Error
| Variant | Description |
|---|---|
DnsResolveFailed(host, err) |
DNS lookup failed |
MxIsEmpty(host) |
No MX records found |
Reject { email, server, response } |
Server rejected the message |
SendErr { email, server, error } |
Send failed |
SmtpAllFailed(host, err) |
All MX servers failed |
TooManyReceived { sender, count } |
Exceeded 30 Received headers |
Standalone Functions
// Send without Received header (for direct sending)
pub async ;
// Create DKIM signer (cached)
;
// Received header utilities
;
;
pub const MAX_RECEIVED_COUNT: u8 = 30;
Directory Structure
src/
├── lib.rs # Entry point, Send struct, concurrent send
├── dkim.rs # DKIM signer with cache
├── error.rs # Error types
├── parse.rs # Received header parsing
├── send.rs # Single domain sending logic
├── smtp.rs # SMTP connection wrapper
└── reject/ # Bounce email generation
├── mod.rs
├── create_tar_zstd.rs
├── encode_mail.rs
└── reject_mail.rs
Tech Stack
mail_send- SMTP protocolidoq/idns- DNS-over-QUIC for MX lookupsk_dkim- DKIM key managementmail-parser- Email parsing for bounce generationexpire_cache+dashmap- DKIM signer cachingasync-scoped- Scoped async tasks for concurrent sending
About
This project is an open-source component of js0.site ⋅ Refactoring the Internet Plan.
We are redefining the development paradigm of the Internet in a componentized way. Welcome to follow us:
smtp_send
支持 DKIM 签名、MX 查询和自动退信处理的 SMTP 邮件发送库。
功能
- DKIM 签名: RSA-SHA256,RFC 6376 头部保护(N+1 签名)
- MX 查询: 通过
idoq使用 DNS-over-QUIC - 并发发送: 按域名分组并行投递
- 故障转移: 失败时尝试多个 MX 服务器
- 退信处理: 自动生成符合 RFC 5321 的拒信报告
- 循环防护: 检查
Received头数量(最大 30)及Auto-Submitted/Return-Path头 - DKIM 缓存: 签名器 600 秒 TTL 缓存
使用
use Send;
use Mail;
async
API
Send
SendResult
Error
| 变体 | 说明 |
|---|---|
DnsResolveFailed(host, err) |
DNS 解析失败 |
MxIsEmpty(host) |
未找到 MX 记录 |
Reject { email, server, response } |
服务器拒绝 |
SendErr { email, server, error } |
发送失败 |
SmtpAllFailed(host, err) |
所有 MX 服务器均失败 |
TooManyReceived { sender, count } |
Received 头超过 30 个 |
独立函数
// 不添加 Received 头直接发送
pub async ;
// 创建 DKIM 签名器(带缓存)
;
// Received 头工具函数
;
;
pub const MAX_RECEIVED_COUNT: u8 = 30;
目录结构
src/
├── lib.rs # 入口,Send 结构体,并发发送
├── dkim.rs # DKIM 签名器及缓存
├── error.rs # 错误类型
├── parse.rs # Received 头解析
├── send.rs # 单域名发送逻辑
├── smtp.rs # SMTP 连接封装
└── reject/ # 退信生成
├── mod.rs
├── create_tar_zstd.rs
├── encode_mail.rs
└── reject_mail.rs
技术栈
mail_send- SMTP 协议idoq/idns- DNS-over-QUIC MX 查询sk_dkim- DKIM 密钥管理mail-parser- 邮件解析(用于退信生成)expire_cache+dashmap- DKIM 签名器缓存async-scoped- 作用域异步任务,用于并发发送
关于
本项目为 js0.site ⋅ 重构互联网计划 的开源组件。
我们正在以组件化的方式重新定义互联网的开发范式,欢迎关注: