Module stub

Source
Expand description

The stub transport logs message envelopes as well as contents. It can be useful for testing purposes.

§Stub Transport

The stub transport logs message envelopes as well as contents. It can be useful for testing purposes.

§Examples

use lettre::{
    message::header::ContentType, transport::stub::StubTransport, Message, Transport,
};

let email = Message::builder()
    .from("NoBody <nobody@domain.tld>".parse()?)
    .reply_to("Yuin <yuin@domain.tld>".parse()?)
    .to("Hei <hei@domain.tld>".parse()?)
    .subject("Happy new year")
    .header(ContentType::TEXT_PLAIN)
    .body(String::from("Be happy!"))?;

let mut sender = StubTransport::new_ok();
sender.send(&email)?;
assert_eq!(
    sender.messages(),
    vec![(
        email.envelope().clone(),
        String::from_utf8(email.formatted()).unwrap()
    )],
);

Structs§

Error
An error returned by the stub transport
StubTransport
This transport logs messages and always returns the given response