#internal #context #resources #header #future #bodies


[mail/core] provides the Mail type for the mail crate (inkl. multipart mime bodies, builder and resource type)

3 releases

Uses old Rust 2015

0.6.2 Mar 26, 2019
0.6.1 Jan 7, 2019
0.6.0 Nov 23, 2018

#308 in Email

Download history 1/week @ 2023-12-11 6/week @ 2023-12-18 21/week @ 2023-12-25 7/week @ 2024-01-08 22/week @ 2024-01-29 10/week @ 2024-02-05 21/week @ 2024-02-12 22/week @ 2024-02-19 48/week @ 2024-02-26 18/week @ 2024-03-04 24/week @ 2024-03-11 19/week @ 2024-03-18 25/week @ 2024-03-25

89 downloads per month
Used in 5 crates


2.5K SLoC


Provides the core mail type Mail for the mail crate.

This crate provides the type called mail as well as ways to create it. It also provides the builder context interface and the Resource type, which is used to represent mail bodies. Especially such which are attachments or embedded images.


extern crate futures;
// Note that the `mail` crate provides a facade re-exporting
// all relevant parts.
extern crate mail_core;
extern crate mail_internals;
extern crate mail_headers;

use std::str;
use futures::Future;

use mail_internals::MailType;

// In the facade this is the `headers` module.
use mail_headers::{

// In the facade this types (and the default_impl module)
// are also exposed at top level
use mail_core::{

fn print_some_mail() -> Result<(), MailError> {
    // Domain will implement `from_str` in the future,
    // currently it doesn't have a validator/parser.
    // So this will become `"example.com".parse()`
    let domain = Domain::from_unchecked("example.com".to_owned());
    // Normally you create this _once per application_.
    let ctx = simple_context::new(domain, "xqi93".parse().expect("we know it's ascii"))
        .expect("this is basically: failed to get cwd from env");

    let mut mail = Mail::plain_text("Hy there! 😁");
    mail.insert_headers(headers! {
        _From: [("I'm Awesome 😁", "bla@examle.com")],
        _To: ["unknow@example.com"],
        Subject: "Hy there message 😁"

    // We don't added any think which needs loading but we could have
    // and all of it would have been loaded concurrent and async.
    let encoded = mail.into_encodable_mail(ctx.clone())

    let mail_str = str::from_utf8(&encoded).unwrap();
    println!("{}", mail_str);

fn main() {

Documentation can be viewed on docs.rs (once it is published).


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~141K SLoC