mail-send
mail-send is a Rust library to build, sign and send e-mail messages via SMTP. It includes the following features:
- Generates e-mail messages conforming to the Internet Message Format standard (RFC 5322).
- Full MIME support (RFC 2045 - 2049) with automatic selection of the most optimal encoding for each message body part.
- DomainKeys Identified Mail (DKIM) Signatures (RFC 6376) with ED25519-SHA256, RSA-SHA256 and RSA-SHA1 support.
- Simple Mail Transfer Protocol (SMTP; RFC 5321) delivery.
- SMTP Service Extension for Secure SMTP over TLS (RFC 3207).
- SMTP Service Extension for Authentication (RFC 4954) with automatic mechanism negotiation (from most secure to least secure):
- CRAM-MD5 (RFC 2195)
- DIGEST-MD5 (RFC 2831; obsolete but still supported)
- XOAUTH2 (Google proprietary)
- LOGIN
- PLAIN
- Full async (requires Tokio).
Usage Example
Send a message via an SMTP server that requires authentication:
// Build a simple multipart message
let message = new
.from
.to
.subject
.html_body
.text_body;
// Connect to the SMTP submissions port, upgrade to TLS and
// authenticate using the provided credentials.
new
.implicit_tls
.credentials
.connect
.await
.unwrap
.send
.await
.unwrap;
Sign a message with DKIM and send it via an SMTP relay server:
// Build a simple text message with a single attachment
let message = new
.from
.to
.subject
.text_body
.attachment;
// Sign an e-mail message using RSA-SHA256
let pk_rsa = from_rsa_pem.unwrap;
let signer = from_key
.domain
.selector
.headers
.expiration; // Number of seconds before this signature expires (optional)
// Connect to an SMTP relay server over TLS.
// Signs each message with the configured DKIM signer.
new
.connect
.await
.unwrap
.send_signed
.await
.unwrap;
More examples of how to build messages are available in the mail-builder
crate.
Please note that this library does not support parsing e-mail messages as this functionality is provided separately by the mail-parser
crate.
Testing
To run the testsuite:
or, to run the testsuite with MIRI:
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Copyright
Copyright (C) 2020-2022, Stalwart Labs Ltd.