summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: ef30887f5fb4178847442bf67c1af90bcb68e8c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! 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
//!
//! ```no_run
//! extern crate futures;
//! //if you use the mail facade use the re-exports from it instead
//! extern crate mail_types;
//! extern crate mail_smtp;
//! #[macro_use] extern crate mail_headers;
//!
//! use futures::Future;
//! use mail_headers::*;
//! use mail_headers::components::Domain;
//! use mail_types::{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()), "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();
//! # }
//! ```
//!
//!
extern crate futures;
extern crate new_tokio_smtp;
extern crate mail_types as mail;
extern crate mail_common;
extern crate mail_headers as headers;
#[macro_use]
extern crate failure;

mod resolve_all;

pub mod error;
mod request;
mod send_mail;

pub use self::request::MailRequest;
#[cfg(feature="extended-api")]
pub use self::request::derive_envelop_data_from_mail;

pub use self::send_mail::{send_mails, SendMailResult};
#[cfg(feature="extended-api")]
pub use self::send_mail::{encode_mails, send_encoded_mails};


pub use new_tokio_smtp::{ConnectionConfig, ConnectionBuilder};
pub use new_tokio_smtp::command::auth;
pub mod misc {
    pub use new_tokio_smtp::ClientId;
    pub use new_tokio_smtp::Domain;
    pub use new_tokio_smtp::AddressLiteral;
}