[
    {
        "uri": "/content/creating-messages/_index",
        "title": "Creating messages",
        "content": "\nCreating messages\n",
        "tags": []
    },
    {
        "uri": "/content/getting-started/_index",
        "title": "Getting started",
        "content": "\nGetting started\n\nThis section explains how to manipulate emails you have created.",
        "tags": []
    },
    {
        "uri": "/content/getting-started/intro",
        "title": "Introduction",
        "content": "\n{{% notice note %}}\nThis documentation is written for lettre 0.7.\nPlease use https://docs.rs/lettre/0.6.2/lettre/ for lettre 0.6.\n{{% /notice%}}\n\nLettre is an email library that allows creating and sending messages. It provides:\n\nAn easy to use email builder\nPluggable email transports\nUnicode support (for emails and transports, including for sender et recipient addresses when compatible)\nSecure defaults (emails are only sent encrypted by default)\n",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/_index",
        "title": "Sending messages",
        "content": "\nSending Messages\n\nThis section explains how to manipulate emails you have created.",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/file",
        "title": "File transport",
        "content": "\nThe file transport writes the emails to the given directory. The name of the file will be\nmessage_id.txt.\nIt can be useful for testing purposes, or if you want to keep track of sent messages.\n\nuse std::env::temp_dir;\n\nuse lettre::file::FileEmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};\n\n// Write to the local temp directory\nlet mut sender = FileEmailTransport::new(temp_dir());\nlet email = SimpleSendableEmail::new(\n                EmailAddress::new(\"user@localhost\".to_string()),\n                vec![EmailAddress::new(\"root@localhost\".to_string())],\n                \"messageid\".tostring(),\n                \"Hello world\".to_string(),\n            );\n\nlet result = sender.send(&email);\nassert!(result.is_ok());\n\nExample result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt:\n\nb7c211bc-9811-45ce-8cd9-68eab575d695: from=user@localhost to=root@localhost\nTo: root@localhost\nFrom: user@localhost\nSubject: Hello\nDate: Sat, 31 Oct 2015 13:42:19 +0100\nMessage-ID: b7c211bc-9811-45ce-8cd9-68eab575d695.lettre@localhost\n\nHello World!\n",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/intro",
        "title": "Introduction",
        "content": "\nThis mailer contains several different transports for your emails. To be sendable, the\nemails have to implement SendableEmail, which is the case for emails created with lettre_email.\n\nThe following transports are available:\n\nThe SmtpTransport uses the SMTP protocol to send the message over the network. It is\n  the prefered way of sending emails.\nThe SendmailTransport uses the sendmail command to send messages. It is an alternative to\n  the SMTP transport.\nThe FileTransport creates a file containing the email content to be sent. It can be used\n  for debugging or if you want to keep all sent emails.\nThe StubTransport is useful for debugging, and only prints the content of the email in the\n  logs.\n",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/sendmail",
        "title": "Sendmail transport",
        "content": "\nThe sendmail transport sends the email using the local sendmail command.\n\nuse lettre::sendmail::SendmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};\n\nlet email = SimpleSendableEmail::new(\n                EmailAddress::new(\"user@localhost\".to_string()),\n                vec![EmailAddress::new(\"root@localhost\".to_string())],\n                \"messageid\".tostring(),\n                \"Hello world\".to_string(),\n            );\n\nlet mut sender = SendmailTransport::new();\nlet result = sender.send(&email);\nassert!(result.is_ok());\n",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/smtp",
        "title": "SMTP transport",
        "content": "\nThis transport uses the SMTP protocol to send emails over the network (locally or remotely).\n\nIt is desinged to be:\n\nSecured: email are encrypted by default\nModern: Unicode support for email content and sender/recipient adresses when compatible\nFast: supports tcp connection reuse\n\nThis client is designed to send emails to a relay server, and should not be used to send\nemails directly to the destination.\n\nThe relay server can be the local email server, a specific host or a third-party service.\n\nSimple example\n\nThis is the most basic example of usage:\n\nuse lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};\n\nlet email = SimpleSendableEmail::new(\n                EmailAddress::new(\"user@localhost\".to_string()),\n                vec![EmailAddress::new(\"root@localhost\".to_string())],\n                \"messageid\".tostring(),\n                \"Hello world\".to_string(),\n            );\n\n// Open a local connection on port 25\nlet mut mailer =\nSmtpTransport::builderunencryptedlocalhost().unwrap().build();\n// Send the email\nlet result = mailer.send(&email);\n\nassert!(result.is_ok());\n\n Complete example\n\nuse lettre::smtp::authentication::{Credentials, Mechanism};\nuse lettre::smtp::SUBMISSION_PORT;\nuse lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};\nuse lettre::smtp::extension::ClientId;\nuse lettre::smtp::ConnectionReuseParameters;\n\nlet email = SimpleSendableEmail::new(\n                EmailAddress::new(\"user@localhost\".to_string()),\n                vec![EmailAddress::new(\"root@localhost\".to_string())],\n                \"messageid\".tostring(),\n                \"Hello world\".to_string(),\n            );\n\n// Connect to a remote server on a custom port\nlet mut mailer = SmtpTransport::simplebuilder(\"server.tld\".tostring()).unwrap()\n    // Set the name sent during EHLO/HELO, default is localhost\n    .helloname(ClientId::Domain(\"my.hostname.tld\".tostring()))\n    // Add credentials for authentication\n    .credentials(Credentials::new(\"username\".tostring(), \"password\".tostring()))\n    // Enable SMTPUTF8 if the server supports it\n    .smtp_utf8(true)\n    // Configure expected authentication mechanism\n    .authentication_mechanism(Mechanism::Plain)\n    // Enable connection reuse\n    .connection_reuse(ConnectionReuseParameters::ReuseUnlimited).build();\n\nlet result_1 = mailer.send(&email);\nassert!(result1.isok());\n\n// The second email will use the same connection\nlet result_2 = mailer.send(&email);\nassert!(result2.isok());\n\n// Explicitly close the SMTP transaction as we enabled connection reuse\nmailer.close();\n\nLower level\n\nYou can also send commands, here is a simple email transaction without\nerror handling:\n\nuse lettre::EmailAddress;\nuse lettre::smtp::SMTP_PORT;\nuse lettre::smtp::client::Client;\nuse lettre::smtp::client::net::NetworkStream;\nuse lettre::smtp::extension::ClientId;\nuse lettre::smtp::commands::*;\n\nlet mut email_client: ClientNetworkStream = Client::new();\nlet _ = emailclient.connect(&(\"localhost\", SMTPPORT), None);\nlet _ = emailclient.smtpcommand(EhloCommand::new(ClientId::new(\"myhostname\".tostring())));\nlet _ = emailclient.smtpcommand(\n            MailCommand::new(Some(EmailAddress::new(\"user@example.com\".to_string())), vec![])\n        );\nlet _ = emailclient.smtpcommand(\n            RcptCommand::new(EmailAddress::new(\"user@example.org\".to_string()), vec![])\n        );\nlet _ = emailclient.smtpcommand(DataCommand);\nlet _ = emailclient.message(Box::new(\"Test email\".asbytes()));\nlet _ = emailclient.smtpcommand(QuitCommand);\n\n",
        "tags": []
    },
    {
        "uri": "/content/sending-messages/stub",
        "title": "Stub transport",
        "content": "\nThe stub transport only logs message envelope and drops the content. It can be useful for\ntesting purposes.\n\nuse lettre::stub::StubEmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};\n\nlet email = SimpleSendableEmail::new(\n                EmailAddress::new(\"user@localhost\".to_string()),\n                vec![EmailAddress::new(\"root@localhost\".to_string())],\n                \"messageid\".tostring(),\n                \"Hello world\".to_string(),\n            );\n\nlet mut sender = StubEmailTransport::new_positive();\nlet result = sender.send(&email);\nassert!(result.is_ok());\n\nWill log (when using a logger like env_logger):\n\nb7c211bc-9811-45ce-8cd9-68eab575d695: from=user@localhost to=root@localhost\n",
        "tags": []
    }
]