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

mail-core

[mail/core] 为 mail crate 提供了 Mail 类型(包括多部分 MIME 主体、构建器和资源类型)

3 个版本

使用旧的 Rust 2015

0.6.2 2019 年 3 月 26 日
0.6.1 2019 年 1 月 7 日
0.6.0 2018 年 11 月 23 日

#322 in 电子邮件

Download history 20/week @ 2024-03-15 22/week @ 2024-03-22 78/week @ 2024-03-29 38/week @ 2024-04-05 22/week @ 2024-04-12 20/week @ 2024-04-19 16/week @ 2024-04-26 21/week @ 2024-05-03 18/week @ 2024-05-10 30/week @ 2024-05-17 20/week @ 2024-05-24 22/week @ 2024-05-31 18/week @ 2024-06-07 23/week @ 2024-06-14 19/week @ 2024-06-21 4/week @ 2024-06-28

66 每月下载
用于 5 crates

MIT/Apache 许可

140KB
2.5K SLoC

mail-core

mail crate 提供了核心邮件类型 Mail


此 crate 提供了名为 mail 的类型,以及创建它的方法。它还提供了构建器上下文接口和 Resource 类型,用于表示邮件主体。特别是附件或嵌入图像这样的。

示例

extern crate futures;
// Note that the `mail` crate provides a facade re-exporting
// all relevant parts.
extern crate mail_core;
extern crate mail_internals;
#[macro_use]
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::{
    headers::*,
    header_components::Domain
};

// In the facade this types (and the default_impl module)
// are also exposed at top level
use mail_core::{
    Mail,
    default_impl::simple_context,
    error::MailError
};

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 😁", "[email protected]")],
        _To: ["[email protected]"],
        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())
        .wait()?
        .encode_into_bytes(MailType::Ascii)?;

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

fn main() {
    print_some_mail().unwrap()
}

文档可以在 docs.rs 上查看(一旦发布)。

许可

许可如下

任选其一。

贡献

除非您明确声明,否则任何有意提交以包含在作品中的贡献,如 Apache-2.0 许可证中定义的,均应如上双许可,无需任何额外条款或条件。

依赖项

~6MB
~129K SLoC