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 mut message = new;
message.from;
message.to;
message.subject;
message.text_body;
message.binary_attachment;
// Write message to memory
let mut output = Vec new;
message.write_to.unwrap;
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.
let mut message = new;
message.from;
// To recipients
message.to;
// BCC recipients using grouped addresses
message.bcc;
// Set RFC and custom headers
message.subject;
message.in_reply_to;
message.header;
// Set HTML and plain text bodies
message.text_body;
message.html_body;
// Include an embedded image as an inline part
message.binary_inline;
// Add a text and a binary attachment
message.text_attachment;
message.binary_attachment;
// Write the message to a file
message
.write_to
.unwrap;
Nested MIME body structures can be created using the body
method:
// Build a nested multipart message
let mut message = new;
message.from;
message.to;
message.subject;
// Define the nested MIME body structure
message.body;
// Write the message to a file
message
.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, Minter Ltd.
See COPYING for the license.