[
    {
        "uri": "/content/creating-messages/_index",
        "title": "Creating messages",
        "content": "\nCreating messages\n\nThis section explains how to create emails.",
        "tags": []
    },
    {
        "uri": "/content/creating-messages/email",
        "title": "Email creation",
        "content": "\nSimple example\n\nThe email part builds email messages. For now, it does not support attachments.\nAn email is built using an EmailBuilder. The simplest email could be:\n\nextern crate lettre_email;\n\nuse lettre_email::EmailBuilder;\n\nfn main() {\n    // Create an email\n    let email = EmailBuilder::new()\n        // Addresses can be specified by the tuple (email, alias)\n        .to((\"user@example.org\", \"Firstname Lastname\"))\n        // ... or by an address only\n        .from(\"user@example.com\")\n        .subject(\"Hi, Hello world\")\n        .text(\"Hello world.\")\n        .build();\n    \n    assert!(email.is_ok());\n}\n\nWhen the build method is called, the EmailBuilder will add the missing headers (like\nMessage-ID or Date) and check for missing necessary ones (like From or To). It will\nthen generate an Email that can be sent.\n\nThe text() method will create a plain text email, while the html() method will create an\nHTML email. You can use the alternative() method to provide both versions, using plain text\nas fallback for the HTML version.\n\n Complete example\n\nBelow is a more complete example, not using method chaining:\n\nextern crate lettre_email;\n\nuse lettre_email::EmailBuilder;\n\nfn main() {\n    let mut builder = EmailBuilder::new();\n    builder.add_to((\"user@example.org\", \"Alias name\"));\n    builder.add_cc((\"user@example.net\", \"Alias name\"));\n    builder.add_from(\"no-reply@example.com\");\n    builder.add_from(\"no-reply@example.eu\");\n    builder.set_sender(\"no-reply@example.com\");\n    builder.set_subject(\"Hello world\");\n    builder.set_alternative(\"h2Hi, Hello world./h2\", \"Hi, Hello world.\");\n    builder.addreplyto(\"contact@example.com\");\n    builder.add_header((\"X-Custom-Header\", \"my header\"));\n    \n    let email = builder.build();\n    assert!(email.is_ok());\n}\n\nSee the EmailBuilder documentation for a complete list of methods.\n\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.8.\nPlease use https://docs.rs/lettre/0.7.0/lettre/ for lettre 0.7.\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\nextern crate lettre;\n\nuse std::env::temp_dir;\n\nuse lettre::file::FileEmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport};\n\nfn main() {\n    // Write to the local temp directory\n    let mut sender = FileEmailTransport::new(temp_dir());\n    let email = SimpleSendableEmail::new(\n                    \"user@localhost\".to_string(),\n                    &[\"root@localhost\".to_string()],\n                    \"messageid\".tostring(),\n                    \"Hello world\".to_string(),\n                ).unwrap();\n    \n    let result = sender.send(&email);\n    assert!(result.is_ok());\n}\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 preferred 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\nextern crate lettre;\n\nuse lettre::sendmail::SendmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport};\n\nfn main() {\n    let email = SimpleSendableEmail::new(\n                    \"user@localhost\".to_string(),\n                    &[\"root@localhost\".to_string()],\n                    \"messageid\".tostring(),\n                    \"Hello world\".to_string(),\n                ).unwrap();\n    \n    let mut sender = SendmailTransport::new();\n    let result = sender.send(&email);\n    assert!(result.is_ok());\n}\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 designed to be:\n\nSecured: email are encrypted by default\nModern: Unicode support for email content and sender/recipient addresses 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\nextern crate lettre;\n\nuse lettre::{SimpleSendableEmail, EmailTransport, SmtpTransport};\n\nfn main() {\n    let email = SimpleSendableEmail::new(\n                    \"user@localhost\".to_string(),\n                    &[\"root@localhost\".to_string()],\n                    \"messageid\".tostring(),\n                    \"Hello world\".to_string(),\n                ).unwrap();\n    \n    // Open a local connection on port 25\n    let mut mailer =\n    SmtpTransport::builderunencryptedlocalhost().unwrap().build();\n    // Send the email\n    let result = mailer.send(&email);\n    \n    assert!(result.is_ok());\n}\n\n Complete example\n\nextern crate lettre;\n\nuse lettre::smtp::authentication::{Credentials, Mechanism};\nuse lettre::{SimpleSendableEmail, EmailTransport, SmtpTransport};\nuse lettre::smtp::extension::ClientId;\nuse lettre::smtp::ConnectionReuseParameters;\n\nfn main() {\n    let email = SimpleSendableEmail::new(\n                    \"user@localhost\".to_string(),\n                    &[\"root@localhost\".to_string()],\n                    \"messageid\".tostring(),\n                    \"Hello world\".to_string(),\n                ).unwrap();\n    \n    // Connect to a remote server on a custom port\n    let mut mailer = SmtpTransport::simple_builder(\"server.tld\").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    \n    let result_1 = mailer.send(&email);\n    assert!(result1.isok());\n    \n    // The second email will use the same connection\n    let result_2 = mailer.send(&email);\n    assert!(result2.isok());\n    \n    // Explicitly close the SMTP transaction as we enabled connection reuse\n    mailer.close();\n}\n\nLower level\n\nYou can also send commands, here is a simple email transaction without\nerror handling:\n\nextern crate lettre;\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\nfn main() {\n    let mut email_client: ClientNetworkStream = Client::new();\n    let _ = emailclient.connect(&(\"localhost\", SMTPPORT), None);\n    let _ = emailclient.command(EhloCommand::new(ClientId::new(\"myhostname\".to_string())));\n    let _ = email_client.command(\n                MailCommand::new(Some(EmailAddress::new(\"user@example.com\".to_string()).unwrap()), vec![])\n            );\n    let _ = email_client.command(\n                RcptCommand::new(EmailAddress::new(\"user@example.org\".to_string()).unwrap(), vec![])\n            );\n    let _ = email_client.command(DataCommand);\n    let _ = emailclient.message(Box::new(\"Test email\".asbytes()));\n    let _ = email_client.command(QuitCommand);\n}\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\nextern crate lettre;\n\nuse lettre::stub::StubEmailTransport;\nuse lettre::{SimpleSendableEmail, EmailTransport};\n\nfn main() {\n    let email = SimpleSendableEmail::new(\n                    \"user@localhost\".to_string(),\n                    &[\"root@localhost\".to_string()],\n                    \"messageid\".tostring(),\n                    \"Hello world\".to_string(),\n                ).unwrap();\n    \n    let mut sender = StubEmailTransport::new_positive();\n    let result = sender.send(&email);\n    assert!(result.is_ok());\n}\n\nWill log (when using a logger like env_logger):\n\nb7c211bc-9811-45ce-8cd9-68eab575d695: from=user@localhost to=root@localhost\n",
        "tags": []
    }
]