#mail-api

mail-smtp

[mail/smtp] combines mail-core with new-tokio-smtp

3 releases

0.2.2 Mar 26, 2019
0.2.1 Mar 4, 2019
0.2.0 Nov 23, 2018

#20 in Email

Download history 6/week @ 2019-01-19 5/week @ 2019-01-26 10/week @ 2019-02-02 7/week @ 2019-02-09 21/week @ 2019-02-16 9/week @ 2019-02-23 54/week @ 2019-03-02 9/week @ 2019-03-09 4/week @ 2019-03-16 49/week @ 2019-03-23 10/week @ 2019-03-30 9/week @ 2019-04-06 2/week @ 2019-04-13 15/week @ 2019-04-20 20/week @ 2019-04-27

66 downloads per month
Used in 2 crates

MIT/Apache

28KB
450 lines

mail-smtp  

Allows sending mail-core Mail's through new-tokio-smtp


This library binds together new-tokio-smtp and the mail crates.

It can be used to send mail given as mail crates Mail instances to a Mail Submission Agent (MSA). It could, theoretically also be used to send to an MX, but this often needs additional functionality for reliable usage which is not part of this crate.

For ease of use this crate re-exports some of the most commonly used parts from new-tokio-smtp including ConnectionConfig, ConnectionBuilder, all authentication commands/methods (the auth module) as well as useful types (in the misc module).

The send_mails function is the simplest way to send a batch of mails. Nevertheless it doesn't directly accept Mail instances, instead it accepts MailRequest instances. This is needed, as the sender/recipient(s) specified through the Mail headers and those used fro smtp mail delivery are not necessary exactly the same (e.g. for bounce back mails and some no-reply setups).

Example

extern crate futures;
//if you use the mail facade use the re-exports from it instead
extern crate mail_core;
extern crate mail_smtp;
#[macro_use] extern crate mail_headers;

use futures::Future;
use mail_headers::*;
use mail_headers::components::Domain;
use mail_core::{Mail, default_impl::simple_context};
use mail_smtp::{send_mails, ConnectionConfig};

fn main() {
    // this is normally done _once per application instance_
    // and then stored in e.g. a lazy_static. Also `Domain`
    // will implement `FromStr` in the future.
    let ctx = simple_context::new(
        Domain::from_unchecked("example.com".to_owned(),
        // This should be "world" unique for the given domain
        // to assure message and content ids are world unique.
        "asdkds".parse().unwrap()
    ).unwrap();

    let mut mail = Mail::plain_text("Some body").unwrap();
    mail.set_headers(headers! {
        _From: ["bla@example.com"],
        _To: ["blub@example.com"],
        Subject: "Some Mail"
    }.unwrap()).unwrap();

    // don't use unencrypted con for anything but testing and
    // simplified examples
    let con_config = ConnectionConfig::build_local_unencrypted().build();

    let fut = send_mails(con_config, vec![mail.into()], ctx);
    let results = fut.wait();
}

Documentation

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

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~6.5MB
~116K SLoC