mail/lib.rs
1//! Facade which re-exports functionality from a number of mail related crates.
2//!
3//! The facade should re-export enough functionality for using the mail carate
4//! to create/modify/encode mail, send them over smtp (feature) or use a handlebars
5//! based template engine to create them from a template (feature).
6//!
7//! Functionality steming from following crates is re-exported:
8//! - `mail-core` provides a `Mail` type and the core functionality
9//! around creating/modifing/encoding mails.
10//! - `mail-headers` provides implementations for the headers of the mail.
11//! This also includes a number of header components which appear in mail
12//! header bodies but are also re-used in other placed (e.g. `MediaType`
13//! stemming from the `Content-Type header or `Domain`).
14//! - `mail-smtp` bindings to `new-tokio-smtp` to make it easier to send
15//! mails over smtp. This also includes functionality to automatically
16//! derive the _smtp_ sender/receiver from the mail if no sender/receiver
17//! is explicitly given (Smtp by it's standard does not use the `From`/`To`
18//! headers of a mail. Instead it treats the mail, including it's headers
19//! mostly as a opaque block of data. But in practice the addresses in
20//! `From`/`To`/`Sender` tend to match the smtp sender/recipient).
21//! - `mail-template` provides a simple way to bind template engine to
22//! generate mails. It has a feature which if enable directly includes
23//! bindings to `handlebars`. This feature is re-exported in the crate
24//! as the `handlebars` feature.
25//! - `mail-internals` provides some shared mostly internal parts the other
26//! crates use. This is normally only needed if you write your own mail
27//! header implementations. But even then the does this crate re-expost
28//! the parts most likely needed (in the `header_encoding` module).
29//!
30//! ## Examples
31//!
32//! ### [`mail_by_hand`](./examples/mail_by_hand.rs)
33//!
34//! Creates and encodes a simple mail without using any fancy helpers, templates or
35//! similar.
36//!
37//! ### [`mail_from_template`](./examples/mail_from_template/main.rs)
38//!
39//! Uses the bindings for the `handlebars` template engine to create a mail, including
40//! alternate bodies and an attachment.
41//!
42//! ### [`send_mail`](./examples/send_mail/main.rs)
43//!
44//! A simple program which queries the user for information and then sends a
45//! (simple) mail to an MSA (Mail Submission Agent). While it is currently limited
46//! to STARTTLS on port 587, Auth Plain and only simple text mails this is a
47//! limitation of this cli program not the mail libraries which can handle other
48//! forms of connecting and authenticating etc.
49//!
50//! Note that this is meant to send data to an MSA NOT a MX (Mail Exchanger), e.g.
51//! `smtp.gmail.com` is a MSA but `gmail-smtp-in.l.google.com` is an MX. Also note
52//! that some mail providers do not accept Auth Plain (at least not without
53//! enabling it in the security settings). The reason for this is that they prefer
54//! that applications do not use username+password for authentication but other
55//! formats e.g. OAuth2 tokens.
56//!
57//! Rest assured that the authentication data is only sent over a TLS encrypted
58//! channel. Still if you don't trust it consider using some throw away or testing
59//! mail service e.g. `ethereal.email`.
60//!
61//! Lastly the examples uses the same unique seed every time, which means that
62//! Message-ID's, and Content-ID's are not guaranteed to be world unique even
63//! through they should (again a limitation of the example not the mail crate).
64//! Nevertheless given that it also doesn't use its "own" domain but a `.test`
65//! domain it can't guarantee world uniqueness anyway and would fail many spam filters,
66//! so if you use it make sure to change this to the right values for your use
67//! case.
68//!
69//! ## Features
70//!
71//! ### `smtp`
72//!
73//! Provides bindings to `new-tokio-smtp` under `mail::smtp` by reexporting the
74//! `mail-smtp` crate
75//!
76//! ### `handlebars`
77//!
78//! Provides a `mail-template` engine implementation using the `handlebars`
79//! crate. It can be found under `mail::template::handlebars::Handlebars`;
80//!
81//!
82//! ### `traceing`
83//!
84//! Enables the `traceing` debugging functionality in the `EncodingBuffer`
85//! from `mail-internals`, this is only used for testing header implementations
86//! and comes with noticeable overhead. **As such this should not be enabled
87//! except for testing header implementations**. Also `EncodingBuffer` isn't
88//! re-exported as it can be seen as an internal part of the implementation
89//! which normally doesn't need to be accessed directly.
90
91#[doc(hidden)]
92pub extern crate mail_internals as internals;
93extern crate mail_headers;
94extern crate mail_core;
95pub extern crate mail_template as template;
96use self::template as mail_template;
97#[cfg(feature="smtp")]
98pub extern crate mail_smtp as smtp;
99
100#[cfg(all(feature="serde", not(feature="serde-impl")))]
101compile_error! {"use feature `serde-impl` instead of pseudo-feature `serde`"}
102
103/// Re-export of all parts of the `mail_core` crate.
104///
105/// Some parts like `error`/`default_impl` will get overridden.
106pub use mail_core::*;
107
108/// re-export of all error types
109///
110/// From:
111/// - `mail-internals`
112/// - `mail-headers`
113/// - `mail-core`
114/// - `mail-template`
115/// - `mail-smtp` (feature: `smtp`)
116pub mod error {
117 pub use crate::internals::error::*;
118 pub use mail_headers::error::*;
119 pub use mail_headers::InvalidHeaderName;
120 pub use mail_core::error::*;
121 pub use mail_template::error::*;
122 #[cfg(feature="smtp")]
123 pub use smtp::error::*;
124}
125
126pub use self::internals::MailType;
127
128/// Re-export of headers from `mail-headers`.
129pub use mail_headers::{
130 headers,
131 header_components,
132
133 HasHeaderName,
134 HeaderKind,
135 HeaderObj,
136 HeaderObjTrait,
137 HeaderObjTraitBoxExt,
138 HeaderTryFrom,
139 HeaderTryInto,
140 MaxOneMarker,
141
142 map as header_map,
143
144 Header,
145 HeaderName,
146 HeaderMap,
147
148 def_headers,
149};
150
151#[doc(hidden)]
152pub use mail_headers::data;
153
154pub use self::header_components::{
155 MediaType,
156 Mailbox,
157 Email,
158 Domain
159};
160
161
162// Re-export some parts of mail-internals useful for writing custom header.
163pub use crate::internals::{encoder as header_encoding};
164
165/// Re-export of the default_impl parts from `mail-core`.
166///
167/// This provides default implementations for a number of traits which might be needed
168/// for using some parts of the crates, e.g. a simple implementation of `BuilderContext`.
169pub mod default_impl {
170 pub use mail_core::default_impl::*;
171}
172
173#[cfg(feature="test-utils")]
174pub mod test_utils {
175 pub use mail_core::test_utils::*;
176}