mail-builder
mail-builder is a flexible e-mail builder library written in Rust that generates RFC5322 compliant e-mail messages. The library has full MIME support and automatically selects the most optimal encoding for each message body part.
Building e-mail messages is straightforward:
// Build a simple text message with a single attachment
let eml = new
.from
.to
.subject
.text_body
.binary_attachment
.write_to_string
.unwrap;
// Print raw message
println!;
More complex messages with grouped addresses, inline parts and multipart/alternative sections can also be easily built:
// Build a multipart message with text and HTML bodies,
// inline parts and attachments.
new
.from
// To recipients
.to
// BCC recipients using grouped addresses
.bcc
// Set RFC and custom headers
.subject
.in_reply_to
.header
// Set HTML and plain text bodies
.text_body
.html_body
// Include an embedded image as an inline part
.binary_inline
.text_attachment
// Add text and binary attachments
.binary_attachment
// Write the message to a file
.write_to
.unwrap;
Nested MIME body structures can be created using the body
method:
// Build a nested multipart message
new
.from
.to
.subject
// Define the nested MIME body structure
.body
// Write the message to a file
.write_to
.unwrap;
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.
See COPYING for the license.