Compare commits

..

10 Commits

Author SHA1 Message Date
Alexis Mousset
648cf4ce5e Prepare 0.10.0-alpha.4 release 2020-11-11 17:18:02 +01:00
Alexis Mousset
4a9d4fbf7e fix(transport-sendmail): Capture sendmail stderr to make possible to debug 2020-11-11 17:14:58 +01:00
Alexis Mousset
a0da9fc2b9 fix(transport-sendmail): Only pass -f option to sendmail when needed 2020-11-11 17:14:58 +01:00
Alexis Mousset
aa31e4fff6 fix(transport-sendmail): Stop argument parsing before destination addresses 2020-11-11 17:14:58 +01:00
Paolo Barbolini
b187885e70 Upgrade to nom 6 2020-11-02 10:00:45 +01:00
Paolo Barbolini
6216fd92c8 Require futures-util ^0.3.7 to avoid RustSec Advisory warning 2020-11-02 10:00:45 +01:00
Manuel Pelloni
0de49c000c Refactor CI configuration and fix building with some combination of features (#494)
* Wip CI refactor, Fix cargo hack test --each-feature

* CI Refactor

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update src/transport/stub/mod.rs

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Adress code review comment

* Update .github/workflows/test.yml

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Adress review comment

* Add necessary sudo command to install postfix

* Set the action name which setup the cache to Setup cache

* Fix delimiter error

* Fix cargo hack test --each-feature

* Remove blanks before no_run

* Remove useless # before imports in doc tests

* Add builder as required feature for all the examples

* Remove blanks before no_run

* Add builder to the test cfg

* Fix building with tokio03-rustls-tls

* Minor improvements

* Use cargo hack only for check in stable

* Improve chache key

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
2020-10-29 21:08:29 +01:00
Paolo Barbolini
b55bcfb6fb Add deps.rs badge (#493) 2020-10-23 11:40:17 +00:00
RotationMatrix
04f064ed5a Add README for examples (#489)
* Add README for examples

* Fix typo in examples/README.md

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Update examples/README.md

Add links to source files and improve wording.

* Fix typos in examples/README.md

* Update examples/README.md

Fix typo.
Add line under title.

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>

* Fix typo in examples/README.md

Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
2020-10-23 13:31:03 +02:00
Benjamin Beckwith
13b48b656d Replace unwrap in doc examples (#491)
Replace any `unwrap` calls in documentation examples by `?` per
the guidance here:
https://rust-lang.github.io/api-guidelines/documentation.html#examples-use--not-try-not-unwrap-c-question-mark
2020-10-23 08:17:39 +00:00
25 changed files with 470 additions and 303 deletions

View File

@@ -6,7 +6,7 @@ jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,107 +1,124 @@
name: Continuous integration
name: CI
on: [push, pull_request]
on:
pull_request:
push:
branches:
- master
jobs:
test:
name: Test
rustfmt:
name: rustfmt / stable
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- 1.45.2
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: sudo DEBIAN_FRONTEND=noninteractive apt-get update
- run: sudo DEBIAN_FRONTEND=noninteractive apt-get -y install postfix
- run: smtp-sink 2525 1000&
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features=native-tls,builder,r2d2,smtp-transport,file-transport,sendmail-transport
- run: rm target/debug/deps/liblettre-*
- uses: actions-rs/cargo@v1
with:
command: test
- run: rm target/debug/deps/liblettre-*
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features=builder,smtp-transport,file-transport,sendmail-transport
- run: rm target/debug/deps/liblettre-*
- uses: actions-rs/cargo@v1
with:
command: test
args: --features=async-std1
- uses: actions-rs/cargo@v1
with:
command: test
args: --features=tokio02
- uses: actions-rs/cargo@v1
with:
command: test
args: --features=tokio03
check:
name: Check
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- 1.45.2
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: check
- name: Checkout
uses: actions/checkout@v2
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Install rust
run: |
rustup update --no-self-update stable
rustup component add rustfmt
- name: cargo fmt
run: cargo fmt --all -- --check
clippy:
name: Clippy
name: clippy / stable
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install rust
run: |
rustup update --no-self-update stable
rustup component add clippy
- name: Run clippy
run: cargo clippy --all-features --all-targets -- -D warnings
check:
name: check / stable
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-check
- name: Install rust
run: rustup update --no-self-update stable
- name: Install cargo hack
run: cargo install cargo-hack --debug
- name: Check with cargo hack
run: cargo hack check --feature-powerset --depth 3
test:
name: test / ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
include:
- name: stable
rust: stable
- name: beta
rust: beta
- name: 1.45.2
rust: 1.45.2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-test-${{ matrix.rust }}
- name: Install rust
run: |
rustup default ${{ matrix.rust }}
rustup update --no-self-update ${{ matrix.rust }}
- name: Install postfix
run: |
DEBIAN_FRONTEND=noninteractive sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get -y install postfix
- name: Run SMTP server
run: smtp-sink 2525 1000&
- name: Test with no default features
run: cargo test --no-default-features
- name: Test with default features
run: cargo test
- name: Test with all features
run: cargo test --all-features
# coverage:
# name: Coverage
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/checkout@v2
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: nightly

View File

@@ -1,6 +1,7 @@
[package]
name = "lettre"
version = "0.10.0-alpha.3" # remember to update html_root_url and README.md
# remember to update html_root_url and README.md (Cargo.toml example and deps.rs badge)
version = "0.10.0-alpha.4"
description = "Email client"
readme = "README.md"
homepage = "https://lettre.rs"
@@ -35,7 +36,7 @@ serde = { version = "1", optional = true, features = ["derive"] }
serde_json = { version = "1", optional = true }
# smtp
nom = { version = "5", optional = true }
nom = { version = "6", default-features = false, features = ["alloc"], optional = true }
r2d2 = { version = "0.8", optional = true } # feature
hostname = { version = "0.3", optional = true } # feature
@@ -46,8 +47,8 @@ webpki = { version = "0.21", optional = true }
webpki-roots = { version = "0.20", optional = true }
# async
futures-io = { version = "0.3", optional = true }
futures-util = { version = "0.3", features = ["io"], optional = true }
futures-io = { version = "0.3.7", optional = true }
futures-util = { version = "0.3.7", features = ["io"], optional = true }
## async-std
async-attributes = { version = "1.1", optional = true }
@@ -101,33 +102,33 @@ rustdoc-args = ["--cfg", "docsrs"]
[[example]]
name = "smtp"
required-features = ["smtp-transport"]
required-features = ["smtp-transport", "builder"]
[[example]]
name = "smtp_tls"
required-features = ["smtp-transport", "native-tls"]
required-features = ["smtp-transport", "native-tls", "builder"]
[[example]]
name = "smtp_starttls"
required-features = ["smtp-transport", "native-tls"]
required-features = ["smtp-transport", "native-tls", "builder"]
[[example]]
name = "smtp_selfsigned"
required-features = ["smtp-transport", "native-tls"]
required-features = ["smtp-transport", "native-tls", "builder"]
[[example]]
name = "tokio02_smtp_tls"
required-features = ["smtp-transport", "tokio02", "tokio02-native-tls"]
required-features = ["smtp-transport", "tokio02", "tokio02-native-tls", "builder"]
[[example]]
name = "tokio02_smtp_starttls"
required-features = ["smtp-transport", "tokio02", "tokio02-native-tls"]
required-features = ["smtp-transport", "tokio02", "tokio02-native-tls", "builder"]
[[example]]
name = "tokio03_smtp_tls"
required-features = ["smtp-transport", "tokio03", "tokio03-native-tls"]
required-features = ["smtp-transport", "tokio03", "tokio03-native-tls", "builder"]
[[example]]
name = "tokio03_smtp_starttls"
required-features = ["smtp-transport", "tokio03", "tokio03-native-tls"]
required-features = ["smtp-transport", "tokio03", "tokio03-native-tls", "builder"]

View File

@@ -27,6 +27,13 @@
</a>
</div>
<div align="center">
<a href="https://deps.rs/crate/lettre/0.10.0-alpha.4">
<img src="https://deps.rs/crate/lettre/0.10.0-alpha.4/status.svg"
alt="dependency status" />
</a>
</div>
---
**NOTE**: this readme refers to the 0.10 version of lettre, which is
@@ -59,7 +66,7 @@ To use this library, add the following to your `Cargo.toml`:
```toml
[dependencies]
lettre = "0.10.0-alpha.3"
lettre = "0.10.0-alpha.4"
```
```rust,no_run

16
examples/README.md Normal file
View File

@@ -0,0 +1,16 @@
# Lettre Examples
This folder contains examples showing how to use lettre in your own projects.
## Examples
- [smtp.rs] - Send an email using a local SMTP daemon on port 25 as a relay.
- [smtp_tls.rs] - Send an email over SMTP encrypted with TLS and authenticating with username and password.
- [smtp_starttls.rs] - Send an email over SMTP with STARTTLS and authenticating with username and password.
- [smtp_selfsigned.rs] - Send an email over SMTP encrypted with TLS using a self-signed certificate and authenticating with username and password.
- The [smtp_tls.rs] and [smtp_starttls.rs] examples also feature `async`hronous implementations powered by [Tokio](https://tokio.rs/).
These files are prefixed with `tokio02_` or `tokio03_`.
[smtp.rs]: ./smtp.rs
[smtp_tls.rs]: ./smtp_tls.rs
[smtp_starttls.rs]: ./smtp_starttls.rs
[smtp_selfsigned.rs]: ./smtp_selfsigned.rs

View File

@@ -32,10 +32,14 @@ impl Envelope {
/// # use lettre::Address;
/// # use lettre::address::Envelope;
///
/// let sender = Address::from_str("from@email.com").unwrap();
/// let recipients = vec![Address::from_str("to@email.com").unwrap()];
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let sender = Address::from_str("from@email.com")?;
/// let recipients = vec![Address::from_str("to@email.com")?];
///
/// let envelope = Envelope::new(Some(sender), recipients);
/// # Ok(())
/// # }
/// ```
///
/// # Errors
@@ -60,11 +64,15 @@ impl Envelope {
/// # use lettre::Address;
/// # use lettre::address::Envelope;
///
/// let sender = Address::from_str("from@email.com").unwrap();
/// let recipients = vec![Address::from_str("to@email.com").unwrap()];
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let sender = Address::from_str("from@email.com")?;
/// let recipients = vec![Address::from_str("to@email.com")?];
///
/// let envelope = Envelope::new(Some(sender), recipients.clone()).unwrap();
/// let envelope = Envelope::new(Some(sender), recipients.clone())?;
/// assert_eq!(envelope.to(), recipients.as_slice());
/// # Ok(())
/// # }
/// ```
pub fn to(&self) -> &[Address] {
self.forward_path.as_slice()
@@ -79,14 +87,18 @@ impl Envelope {
/// # use lettre::Address;
/// # use lettre::address::Envelope;
///
/// let sender = Address::from_str("from@email.com").unwrap();
/// let recipients = vec![Address::from_str("to@email.com").unwrap()];
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let sender = Address::from_str("from@email.com")?;
/// let recipients = vec![Address::from_str("to@email.com")?];
///
/// let envelope = Envelope::new(Some(sender), recipients.clone()).unwrap();
/// let envelope = Envelope::new(Some(sender), recipients.clone())?;
/// assert!(envelope.from().is_some());
///
/// let senderless = Envelope::new(None, recipients.clone()).unwrap();
/// let senderless = Envelope::new(None, recipients.clone())?;
/// assert!(senderless.from().is_none());
/// # Ok(())
/// # }
/// ```
pub fn from(&self) -> Option<&Address> {
self.reverse_path.as_ref()

View File

@@ -24,7 +24,11 @@ use std::{
///
/// ```
/// # use lettre::Address;
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// # Ok(())
/// # }
/// ```
///
/// You can also create an `Address` from a string literal by parsing it:
@@ -32,7 +36,11 @@ use std::{
/// ```
/// use std::str::FromStr;
/// # use lettre::Address;
/// let address = Address::from_str("example@email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::from_str("example@email.com")?;
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Address {
@@ -86,9 +94,13 @@ impl Address {
/// ```
/// use lettre::Address;
///
/// let address = Address::new("example", "email.com").unwrap();
/// let expected: Address = "example@email.com".parse().unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// let expected: Address = "example@email.com".parse()?;
/// assert_eq!(expected, address);
/// # Ok(())
/// # }
/// ```
pub fn new<U: AsRef<str>, D: AsRef<str>>(user: U, domain: D) -> Result<Self, AddressError> {
(user, domain).try_into()
@@ -101,8 +113,12 @@ impl Address {
/// ```
/// use lettre::Address;
///
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// assert_eq!("example", address.user());
/// # Ok(())
/// # }
/// ```
pub fn user(&self) -> &str {
&self.serialized[..self.at_start]
@@ -115,8 +131,12 @@ impl Address {
/// ```
/// use lettre::Address;
///
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// assert_eq!("email.com", address.domain());
/// # Ok(())
/// # }
/// ```
pub fn domain(&self) -> &str {
&self.serialized[self.at_start + 1..]

View File

@@ -27,7 +27,7 @@
//! * **serde**: Serialization/Deserialization of entities
//! * **hostname**: Ability to try to use actual hostname in SMTP transaction
#![doc(html_root_url = "https://docs.rs/crate/lettre/0.10.0-alpha.3")]
#![doc(html_root_url = "https://docs.rs/crate/lettre/0.10.0-alpha.4")]
#![doc(html_favicon_url = "https://lettre.rs/favicon.ico")]
#![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/15113230?v=4")]
#![forbid(unsafe_code)]
@@ -163,6 +163,7 @@ pub trait Tokio03Transport {
}
#[cfg(test)]
#[cfg(feature = "builder")]
mod test {
use super::*;
use crate::message::{header, Mailbox, Mailboxes};

View File

@@ -21,15 +21,23 @@ use std::{
///
/// ```
/// # use lettre::{Address, message::Mailbox};
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// let mailbox = Mailbox::new(None, address);
/// # Ok(())
/// # }
/// ```
///
/// You can also create one from a string literal:
///
/// ```
/// # use lettre::message::Mailbox;
/// let mailbox: Mailbox = "John Smith <example@email.com>".parse().unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let mailbox: Mailbox = "John Smith <example@email.com>".parse()?;
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Mailbox {
@@ -48,8 +56,12 @@ impl Mailbox {
/// ```
/// use lettre::{Address, message::Mailbox};
///
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// let mailbox = Mailbox::new(None, address);
/// # Ok(())
/// # }
/// ```
pub fn new(name: Option<String>, email: Address) -> Self {
Mailbox { name, email }
@@ -153,8 +165,12 @@ impl Mailboxes {
/// ```
/// use lettre::{Address, message::{Mailbox, Mailboxes}};
///
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// let mut mailboxes = Mailboxes::new().with(Mailbox::new(None, address));
/// # Ok(())
/// # }
/// ```
pub fn with(mut self, mbox: Mailbox) -> Self {
self.0.push(mbox);
@@ -168,9 +184,13 @@ impl Mailboxes {
/// ```
/// use lettre::{Address, message::{Mailbox, Mailboxes}};
///
/// let address = Address::new("example", "email.com").unwrap();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let address = Address::new("example", "email.com")?;
/// let mut mailboxes = Mailboxes::new();
/// mailboxes.push(Mailbox::new(None, address));
/// # Ok(())
/// # }
/// ```
pub fn push(&mut self, mbox: Mailbox) {
self.0.push(mbox);
@@ -183,14 +203,18 @@ impl Mailboxes {
/// ```
/// use lettre::{Address, message::{Mailbox, Mailboxes}};
///
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let empty = Mailboxes::new();
/// assert!(empty.into_single().is_none());
///
/// let mut mailboxes = Mailboxes::new();
/// let address = Address::new("example", "email.com").unwrap();
/// let address = Address::new("example", "email.com")?;
///
/// mailboxes.push(Mailbox::new(None, address));
/// assert!(mailboxes.into_single().is_some());
/// # Ok(())
/// # }
/// ```
pub fn into_single(self) -> Option<Mailbox> {
self.into()
@@ -203,12 +227,14 @@ impl Mailboxes {
/// ```
/// use lettre::{Address, message::{Mailbox, Mailboxes}};
///
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let mut mailboxes = Mailboxes::new();
///
/// let address = Address::new("example", "email.com").unwrap();
/// let address = Address::new("example", "email.com")?;
/// mailboxes.push(Mailbox::new(None, address));
///
/// let address = Address::new("example", "email.com").unwrap();
/// let address = Address::new("example", "email.com")?;
/// mailboxes.push(Mailbox::new(None, address));
///
/// let mut iter = mailboxes.iter();
@@ -217,6 +243,8 @@ impl Mailboxes {
/// assert!(iter.next().is_some());
///
/// assert!(iter.next().is_none());
/// # Ok(())
/// # }
/// ```
pub fn iter(&self) -> Iter<'_, Mailbox> {
self.0.iter()

View File

@@ -90,10 +90,14 @@ impl Default for SinglePartBuilder {
/// ```
/// use lettre::message::{SinglePart, header};
///
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let part = SinglePart::builder()
/// .header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
/// .header(header::ContentType("text/plain; charset=utf8".parse()?))
/// .header(header::ContentTransferEncoding::Binary)
/// .body("Текст письма в уникоде");
/// # Ok(())
/// # }
/// ```
///
#[derive(Debug, Clone)]

View File

@@ -15,13 +15,16 @@
//! ```rust
//! use lettre::message::Message;
//!
//! # use std::error::Error;
//! # fn main() -> Result<(), Box<dyn Error>> {
//! let m = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//! # Ok(())
//! # }
//! ```
//!
//! Will produce:
@@ -46,19 +49,22 @@
//! ```rust
//! use lettre::message::{header, Message, SinglePart, Part};
//!
//! # use std::error::Error;
//! # fn main() -> Result<(), Box<dyn Error>> {
//! let m = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .singlepart(
//! SinglePart::builder()
//! .header(header::ContentType(
//! "text/plain; charset=utf8".parse().unwrap(),
//! "text/plain; charset=utf8".parse()?,
//! )).header(header::ContentTransferEncoding::QuotedPrintable)
//! .body("Привет, мир!"),
//! )
//! .unwrap();
//! )?;
//! # Ok(())
//! # }
//! ```
//!
//! The body will be encoded using selected `Content-Transfer-Encoding`.
@@ -83,10 +89,12 @@
//! ```rust
//! use lettre::message::{header, Message, MultiPart, SinglePart, Part};
//!
//! # use std::error::Error;
//! # fn main() -> Result<(), Box<dyn Error>> {
//! let m = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .multipart(
//! MultiPart::mixed()
@@ -94,19 +102,19 @@
//! MultiPart::alternative()
//! .singlepart(
//! SinglePart::quoted_printable()
//! .header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
//! .header(header::ContentType("text/plain; charset=utf8".parse()?))
//! .body("Привет, мир!")
//! )
//! .multipart(
//! MultiPart::related()
//! .singlepart(
//! SinglePart::eight_bit()
//! .header(header::ContentType("text/html; charset=utf8".parse().unwrap()))
//! .header(header::ContentType("text/html; charset=utf8".parse()?))
//! .body("<p><b>Hello</b>, <i>world</i>! <img src=smile.png></p>")
//! )
//! .singlepart(
//! SinglePart::base64()
//! .header(header::ContentType("image/png".parse().unwrap()))
//! .header(header::ContentType("image/png".parse()?))
//! .header(header::ContentDisposition {
//! disposition: header::DispositionType::Inline,
//! parameters: vec![],
@@ -117,7 +125,7 @@
//! )
//! .singlepart(
//! SinglePart::seven_bit()
//! .header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
//! .header(header::ContentType("text/plain; charset=utf8".parse()?))
//! .header(header::ContentDisposition {
//! disposition: header::DispositionType::Attachment,
//! parameters: vec![
@@ -129,7 +137,9 @@
//! })
//! .body("int main() { return 0; }")
//! )
//! ).unwrap();
//! )?;
//! # Ok(())
//! # }
//! ```
//!
//! ```sh

View File

@@ -5,66 +5,79 @@
//! ## Sync example
//!
//! ```rust
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "file-transport", feature = "builder"))]
//! # fn main() -> Result<(), Box<dyn Error>> {
//! use std::env::temp_dir;
//! use lettre::{Transport, Message, FileTransport};
//!
//! // Write to the local temp directory
//! let sender = FileTransport::new(temp_dir());
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let result = sender.send(&email);
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//!
//! # #[cfg(not(all(feature = "file-transport", feature = "builder")))]
//! # fn main() {}
//! ```
//!
//!
//! ## Async tokio 0.2
//!
//! ```rust
//! # #[cfg(feature = "tokio02")]
//! # async fn run() {
//! ```rust,no_run
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "tokio02", feature = "file-transport", feature = "builder"))]
//! # async fn run() -> Result<(), Box<dyn Error>> {
//! use std::env::temp_dir;
//! use lettre::{Tokio02Transport, Message, FileTransport};
//!
//! // Write to the local temp directory
//! let sender = FileTransport::new(temp_dir());
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let result = sender.send(email).await;
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! ```
//!
//! ## Async async-std 1.x
//!
//! ```rust
//! # #[cfg(feature = "async-std1")]
//! # async fn run() {
//! ```rust,no_run
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "async-std1", feature = "file-transport", feature = "builder"))]
//! # async fn run() -> Result<(), Box<dyn Error>> {
//! use std::env::temp_dir;
//! use lettre::{AsyncStd1Transport, Message, FileTransport};
//!
//! // Write to the local temp directory
//! let sender = FileTransport::new(temp_dir());
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let result = sender.send(email).await;
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! ```
//!

View File

@@ -3,60 +3,72 @@
//! ## Sync example
//!
//! ```rust
//! use lettre::{Message, Transport, SendmailTransport};
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "sendmail-transport", feature = "builder"))]
//! # fn main() -> Result<(), Box<dyn Error>> {
//! # use lettre::{Message, Transport, SendmailTransport};
//!
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let sender = SendmailTransport::new();
//! let result = sender.send(&email);
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//!
//! # #[cfg(not(all(feature = "sendmail-transport", feature = "builder")))]
//! # fn main() {}
//! ```
//!
//! ## Async tokio 0.2 example
//!
//! ```rust
//! # #[cfg(feature = "tokio02")]
//! # async fn run() {
//! ```rust,no_run
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "tokio02", feature = "sendmail-transport", feature = "builder"))]
//! # async fn run() -> Result<(), Box<dyn Error>> {
//! use lettre::{Message, Tokio02Transport, SendmailTransport};
//!
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let sender = SendmailTransport::new();
//! let result = sender.send(email).await;
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! ```
//!
//! ## Async async-std 1.x example
//!
//!```rust
//! # #[cfg(feature = "async-std1")]
//! # async fn run() {
//!```rust,no_run
//! # use std::error::Error;
//!
//! # #[cfg(all(feature = "async-std1", feature = "sendmail-transport", feature = "builder"))]
//! # async fn run() -> Result<(), Box<dyn Error>> {
//! use lettre::{Message, AsyncStd1Transport, SendmailTransport};
//!
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let sender = SendmailTransport::new();
//! let result = sender.send(email).await;
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! ```
@@ -105,12 +117,15 @@ impl SendmailTransport {
fn command(&self, envelope: &Envelope) -> Command {
let mut c = Command::new(&self.command);
c.arg("-i")
.arg("-f")
.arg(envelope.from().map(|f| f.as_ref()).unwrap_or("\"\""))
c.arg("-i");
if let Some(from) = envelope.from() {
c.arg("-f").arg(from);
}
c.arg("--")
.args(envelope.to())
.stdin(Stdio::piped())
.stdout(Stdio::piped());
.stdout(Stdio::piped())
.stderr(Stdio::piped());
c
}
@@ -120,12 +135,15 @@ impl SendmailTransport {
let mut c = Command::new(&self.command);
c.kill_on_drop(true);
c.arg("-i")
.arg("-f")
.arg(envelope.from().map(|f| f.as_ref()).unwrap_or("\"\""))
c.arg("-i");
if let Some(from) = envelope.from() {
c.arg("-f").arg(from);
}
c.arg("--")
.args(envelope.to())
.stdin(Stdio::piped())
.stdout(Stdio::piped());
.stdout(Stdio::piped())
.stderr(Stdio::piped());
c
}
@@ -135,12 +153,15 @@ impl SendmailTransport {
let mut c = Command::new(&self.command);
c.kill_on_drop(true);
c.arg("-i")
.arg("-f")
.arg(envelope.from().map(|f| f.as_ref()).unwrap_or("\"\""))
c.arg("-i");
if let Some(from) = envelope.from() {
c.arg("-f").arg(from);
}
c.arg("--")
.args(envelope.to())
.stdin(Stdio::piped())
.stdout(Stdio::piped());
.stdout(Stdio::piped())
.stderr(Stdio::piped());
c
}
}

View File

@@ -268,11 +268,11 @@ impl AsyncSmtpConnection {
return Err(response.into());
}
Err(nom::Err::Failure(e)) => {
return Err(Error::Parsing(e.1));
return Err(Error::Parsing(e.code));
}
Err(nom::Err::Incomplete(_)) => { /* read more */ }
Err(nom::Err::Error(e)) => {
return Err(Error::Parsing(e.1));
return Err(Error::Parsing(e.code));
}
}
}

View File

@@ -1,4 +1,4 @@
#[cfg(feature = "tokio02-rustls-tls")]
#[cfg(any(feature = "tokio02-rustls-tls", feature = "tokio03-rustls-tls"))]
use std::sync::Arc;
use std::{
net::{Shutdown, SocketAddr},

View File

@@ -253,11 +253,11 @@ impl SmtpConnection {
return Err(response.into());
}
Err(nom::Err::Failure(e)) => {
return Err(Error::Parsing(e.1));
return Err(Error::Parsing(e.code));
}
Err(nom::Err::Incomplete(_)) => { /* read more */ }
Err(nom::Err::Error(e)) => {
return Err(Error::Parsing(e.1));
return Err(Error::Parsing(e.code));
}
}
}

View File

@@ -3,21 +3,24 @@
//! `SmtpConnection` allows manually sending SMTP commands.
//!
//! ```rust,no_run
//! # use std::error::Error;
//!
//! # #[cfg(feature = "smtp-transport")]
//! # {
//! # fn main() -> Result<(), Box<dyn Error>> {
//! use lettre::transport::smtp::{SMTP_PORT, extension::ClientId, commands::*, client::SmtpConnection};
//!
//! let hello = ClientId::Domain("my_hostname".to_string());
//! let mut client = SmtpConnection::connect(&("localhost", SMTP_PORT), None, &hello, None).unwrap();
//! let mut client = SmtpConnection::connect(&("localhost", SMTP_PORT), None, &hello, None)?;
//! client.command(
//! Mail::new(Some("user@example.com".parse().unwrap()), vec![])
//! ).unwrap();
//! Mail::new(Some("user@example.com".parse()?), vec![])
//! )?;
//! client.command(
//! Rcpt::new("user@example.org".parse().unwrap(), vec![])
//! ).unwrap();
//! client.command(Data).unwrap();
//! client.message("Test email".as_bytes()).unwrap();
//! client.command(Quit).unwrap();
//! Rcpt::new("user@example.org".parse()?, vec![])
//! )?;
//! client.command(Data)?;
//! client.message("Test email".as_bytes())?;
//! client.command(Quit)?;
//! # Ok(())
//! # }
//! ```

View File

@@ -109,12 +109,12 @@ impl From<native_tls::Error> for Error {
}
}
impl From<nom::Err<(&str, nom::error::ErrorKind)>> for Error {
fn from(err: nom::Err<(&str, nom::error::ErrorKind)>) -> Error {
impl From<nom::Err<nom::error::Error<&str>>> for Error {
fn from(err: nom::Err<nom::error::Error<&str>>) -> Error {
Parsing(match err {
nom::Err::Incomplete(_) => nom::error::ErrorKind::Complete,
nom::Err::Failure((_, k)) => k,
nom::Err::Error((_, k)) => k,
nom::Err::Failure(e) => e.code,
nom::Err::Error(e) => e.code,
})
}
}

View File

@@ -31,17 +31,16 @@
//! This is the most basic example of usage:
//!
//! ```rust,no_run
//! # #[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
//! # {
//! # #[cfg(all(feature = "builder", any(feature = "native-tls", feature = "rustls-tls")))]
//! # fn test() -> Result<(), Box<dyn std::error::Error>> {
//! use lettre::{Message, Transport, SmtpTransport};
//!
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! // Create TLS transport on port 465
//! let sender = SmtpTransport::relay("smtp.example.com")
@@ -50,6 +49,7 @@
//! // Send the email via remote relay
//! let result = sender.send(&email);
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! ```
@@ -64,24 +64,24 @@
//!
//! let email_1 = Email::new(
//! Envelope::new(
//! Some(EmailAddress::new("user@localhost".to_string()).unwrap()),
//! vec![EmailAddress::new("root@localhost".to_string()).unwrap()],
//! ).unwrap(),
//! Some(EmailAddress::new("user@localhost".to_string())?),
//! vec![EmailAddress::new("root@localhost".to_string())?],
//! )?,
//! "id1".to_string(),
//! "Hello world".to_string().into_bytes(),
//! );
//!
//! let email_2 = Email::new(
//! Envelope::new(
//! Some(EmailAddress::new("user@localhost".to_string()).unwrap()),
//! vec![EmailAddress::new("root@localhost".to_string()).unwrap()],
//! ).unwrap(),
//! Some(EmailAddress::new("user@localhost".to_string())?),
//! vec![EmailAddress::new("root@localhost".to_string())?],
//! )?,
//! "id2".to_string(),
//! "Hello world a second time".to_string().into_bytes(),
//! );
//!
//! // Connect to a remote server on a custom port
//! let mut mailer = SmtpClient::new_simple("server.tld").unwrap()
//! let mut mailer = SmtpClient::new_simple("server.tld")?
//! // Set the name sent during EHLO/HELO, default is `localhost`
//! .hello_name(ClientId::Domain("my.hostname.tld".to_string()))
//! // Add credentials for authentication
@@ -120,9 +120,9 @@
//!
//! let email = Email::new(
//! Envelope::new(
//! Some(EmailAddress::new("user@localhost".to_string()).unwrap()),
//! vec![EmailAddress::new("root@localhost".to_string()).unwrap()],
//! ).unwrap(),
//! Some(EmailAddress::new("user@localhost".to_string())?),
//! vec![EmailAddress::new("root@localhost".to_string())?],
//! )?,
//! "message_id".to_string(),
//! "Hello world".to_string().into_bytes(),
//! );
@@ -132,12 +132,12 @@
//! let tls_parameters =
//! ClientTlsParameters::new(
//! "smtp.example.com".to_string(),
//! tls_builder.build().unwrap()
//! tls_builder.build()?
//! );
//!
//! let mut mailer = SmtpClient::new(
//! ("smtp.example.com", 465), ClientSecurity::Wrapper(tls_parameters)
//! ).unwrap()
//! )?
//! .authentication_mechanism(Mechanism::Login)
//! .credentials(Credentials::new(
//! "example_username".to_string(), "example_password".to_string()
@@ -164,6 +164,7 @@ pub use self::async_transport::{
};
#[cfg(feature = "r2d2")]
pub use self::pool::PoolConfig;
#[cfg(feature = "r2d2")]
pub(crate) use self::transport::SmtpClient;
pub use self::{
error::Error,

View File

@@ -238,7 +238,10 @@ pub(crate) fn parse_response(i: &str) -> IResult<&str, Response> {
// Check that all codes are equal.
if !lines.iter().all(|&(code, _, _)| code == last_code) {
return Err(nom::Err::Failure(("", nom::error::ErrorKind::Not)));
return Err(nom::Err::Failure(nom::error::Error::new(
"",
nom::error::ErrorKind::Not,
)));
}
// Extract text from lines, and append last line.

View File

@@ -7,20 +7,26 @@
//! testing purposes.
//!
//! ```rust
//! # #[cfg(feature = "builder")]
//! # {
//! use lettre::{Message, Transport};
//! use lettre::transport::stub::StubTransport;
//!
//! # use std::error::Error;
//! # fn main() -> Result<(), Box<dyn Error>> {
//! let email = Message::builder()
//! .from("NoBody <nobody@domain.tld>".parse().unwrap())
//! .reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
//! .to("Hei <hei@domain.tld>".parse().unwrap())
//! .from("NoBody <nobody@domain.tld>".parse()?)
//! .reply_to("Yuin <yuin@domain.tld>".parse()?)
//! .to("Hei <hei@domain.tld>".parse()?)
//! .subject("Happy new year")
//! .body("Be happy!")
//! .unwrap();
//! .body("Be happy!")?;
//!
//! let mut sender = StubTransport::new_ok();
//! let result = sender.send(&email);
//! assert!(result.is_ok());
//! # Ok(())
//! # }
//! # }
//! ```
use crate::address::Envelope;

View File

@@ -1,5 +1,5 @@
#[cfg(test)]
#[cfg(feature = "file-transport")]
#[cfg(all(feature = "file-transport", feature = "builder"))]
mod test {
use lettre::{transport::file::FileTransport, Message};
use std::{

View File

@@ -1,5 +1,5 @@
#[cfg(test)]
#[cfg(feature = "sendmail-transport")]
#[cfg(all(feature = "sendmail-transport", feature = "builder"))]
mod test {
use lettre::{transport::sendmail::SendmailTransport, Message};

View File

@@ -1,5 +1,5 @@
#[cfg(test)]
#[cfg(feature = "smtp-transport")]
#[cfg(all(feature = "smtp-transport", feature = "builder"))]
mod test {
use lettre::{Message, SmtpTransport, Transport};

View File

@@ -1,61 +1,65 @@
use lettre::{transport::stub::StubTransport, Message};
#[cfg(test)]
#[cfg(feature = "builder")]
mod test {
use lettre::{transport::stub::StubTransport, Message};
#[cfg(feature = "tokio02")]
use tokio02_crate as tokio;
#[cfg(feature = "tokio02")]
use tokio02_crate as tokio;
#[test]
fn stub_transport() {
use lettre::Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.body("Be happy!")
.unwrap();
#[test]
fn stub_transport() {
use lettre::Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.body("Be happy!")
.unwrap();
sender_ok.send(&email).unwrap();
sender_ko.send(&email).unwrap_err();
}
#[cfg(feature = "async-std1")]
#[async_attributes::test]
async fn stub_transport_asyncstd1() {
use lettre::AsyncStd1Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.date("Tue, 15 Nov 1994 08:12:31 GMT".parse().unwrap())
.body("Be happy!")
.unwrap();
sender_ok.send(email.clone()).await.unwrap();
sender_ko.send(email).await.unwrap_err();
}
#[cfg(feature = "tokio02")]
#[tokio::test]
async fn stub_transport_tokio02() {
use lettre::Tokio02Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.date("Tue, 15 Nov 1994 08:12:31 GMT".parse().unwrap())
.body("Be happy!")
.unwrap();
sender_ok.send(email.clone()).await.unwrap();
sender_ko.send(email).await.unwrap_err();
sender_ok.send(&email).unwrap();
sender_ko.send(&email).unwrap_err();
}
#[cfg(feature = "async-std1")]
#[async_attributes::test]
async fn stub_transport_asyncstd1() {
use lettre::AsyncStd1Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.date("Tue, 15 Nov 1994 08:12:31 GMT".parse().unwrap())
.body("Be happy!")
.unwrap();
sender_ok.send(email.clone()).await.unwrap();
sender_ko.send(email).await.unwrap_err();
}
#[cfg(feature = "tokio02")]
#[tokio::test]
async fn stub_transport_tokio02() {
use lettre::Tokio02Transport;
let sender_ok = StubTransport::new_ok();
let sender_ko = StubTransport::new_error();
let email = Message::builder()
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.date("Tue, 15 Nov 1994 08:12:31 GMT".parse().unwrap())
.body("Be happy!")
.unwrap();
sender_ok.send(email.clone()).await.unwrap();
sender_ko.send(email).await.unwrap_err();
}
}