[][src]Module lettre::transport::file

This is supported on crate feature file-transport only.

The file transport writes the emails to the given directory. The name of the file will be message_id.json. It can be useful for testing purposes, or if you want to keep track of sent messages.

Sync example


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()?)
    .reply_to("Yuin <yuin@domain.tld>".parse()?)
    .to("Hei <hei@domain.tld>".parse()?)
    .subject("Happy new year")
    .body("Be happy!")?;

let result = sender.send(&email);
assert!(result.is_ok());

Async tokio 0.2


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()?)
    .reply_to("Yuin <yuin@domain.tld>".parse()?)
    .to("Hei <hei@domain.tld>".parse()?)
    .subject("Happy new year")
    .body("Be happy!")?;

let result = sender.send(email).await;
assert!(result.is_ok());

Async async-std 1.x


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()?)
    .reply_to("Yuin <yuin@domain.tld>".parse()?)
    .to("Hei <hei@domain.tld>".parse()?)
    .subject("Happy new year")
    .body("Be happy!")?;

let result = sender.send(email).await;
assert!(result.is_ok());

Example result

{
  "envelope": {
    "forward_path": [
      "hei@domain.tld"
    ],
    "reverse_path": "nobody@domain.tld"
  },
  "raw_message": null,
  "message": "From: NoBody <nobody@domain.tld>\r\nReply-To: Yuin <yuin@domain.tld>\r\nTo: Hei <hei@domain.tld>\r\nSubject: Happy new year\r\nDate: Tue, 18 Aug 2020 22:50:17 GMT\r\n\r\nBe happy!"
}

Structs

FileTransport

Writes the content and the envelope information to a file

Enums

Error

An enum of all error kinds.