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
idot - 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 |
|---|---|
DkimInit(host) |
DKIM signer initialization failed |
DnsResolveFailed(host, err) |
DNS lookup failed |
MxIsEmpty(host) |
No MX records found |
Reject(Reject) |
Server rejected the message |
SendErr(SendErr) |
Send failed |
SmtpAllFailed(host, err) |
All MX servers failed |
TooManyReceived(sender) |
Exceeded 30 Received headers |
Standalone Functions
// Send without Received header (for direct sending)
pub async ;
// Create DKIM signer (cached), returns None on failure
;
// Check if Received headers exceed limit
;
// Add Received header
;
pub const MAX_RECEIVED: usize = 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 protocolidot/idns- DNS-over-QUIC for MX lookupsk_dkim- DKIM key managementmail-parser- Email parsing for bounce generationpapaya- DKIM signer cachingasync-scoped- Scoped async tasks for concurrent sending
About
This library is developed by WebC.site.
WebC.site: A new paradigm of web development for AI
smtp_send
支持 DKIM 签名、MX 查询和自动退信处理的 SMTP 邮件发送库。
功能
- DKIM 签名: RSA-SHA256,RFC 6376 头部保护(N+1 签名)
- MX 查询: 通过
idot使用 DNS-over-QUIC - 并发发送: 按域名分组并行投递
- 故障转移: 失败时尝试多个 MX 服务器
- 退信处理: 自动生成符合 RFC 5321 的拒信报告
- 循环防护: 检查
Received头数量(最大 30)及Auto-Submitted/Return-Path头 - DKIM 缓存: 签名器 600 秒 TTL 缓存
使用
use Send;
use Mail;
async
API
Send
SendResult
Error
| 变体 | 说明 |
|---|---|
DkimInit(host) |
DKIM 签名器初始化失败 |
DnsResolveFailed(host, err) |
DNS 解析失败 |
MxIsEmpty(host) |
未找到 MX 记录 |
Reject(Reject) |
服务器拒绝 |
SendErr(SendErr) |
发送失败 |
SmtpAllFailed(host, err) |
所有 MX 服务器均失败 |
TooManyReceived(sender) |
Received 头超过 30 个 |
独立函数
// 不添加 Received 头直接发送
pub async ;
// 创建 DKIM 签名器(带缓存),失败返回 None
;
// 检查 Received 头是否超限
;
// 添加 Received 头
;
pub const MAX_RECEIVED: usize = 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 协议idot/idns- DNS-over-QUIC MX 查询sk_dkim- DKIM 密钥管理mail-parser- 邮件解析(用于退信生成)papaya- DKIM 签名器缓存async-scoped- 作用域异步任务,用于并发发送
关于
本库由 WebC.site 开发。
WebC.site : 面向人工智能的网站开发新范式