File Transport

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

extern crate lettre;

use std::env::temp_dir;

use lettre::file::FileTransport;
use lettre::{Transport, Envelope, EmailAddress, SendableEmail};

fn main() {
    // Write to the local temp directory
    let mut sender = FileTransport::new(temp_dir());
    let email = SendableEmail::new(
        "Hello world".to_string().into_bytes(),
    let result = sender.send(email);

Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt:

b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
To: <root@localhost>
From: <user@localhost>
Subject: Hello
Date: Sat, 31 Oct 2015 13:42:19 +0100
Message-ID: <b7c211bc-9811-45ce-8cd9-68eab575d695.lettre@localhost>

Hello World!