fix(doc): Update doc and specify the target version
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
<pubDate>Sun, 21 May 2017 23:46:17 +0200</pubDate>
|
||||
|
||||
<guid>https://lettre.github.io/lettre/getting-started/intro/</guid>
|
||||
<description>Lettre is an email library that allows creating and sending messages. It provides:
|
||||
<description>This documentation is written for lettre 0.7, wich has not been released yet. Please use https://docs.rs/lettre/0.6.2/lettre/ for lettre 0.6.
|
||||
Lettre is an email library that allows creating and sending messages. It provides:
|
||||
An easy to use email builder Pluggable email transports Unicode support (for emails and transports, including for sender et recipient addresses when compatible) Secure defaults (emails are only sent encrypted by default) </description>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -268,6 +268,11 @@
|
||||
<h1>Introduction</h1>
|
||||
|
||||
|
||||
<div class="notices note" ><p>This documentation is written for lettre 0.7, wich has not been released yet.
|
||||
Please use <a href="https://docs.rs/lettre/0.6.2/lettre/">https://docs.rs/lettre/0.6.2/lettre/</a> for lettre 0.6.</p>
|
||||
</div>
|
||||
|
||||
|
||||
<p>Lettre is an email library that allows creating and sending messages. It provides:</p>
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<pubDate>Sun, 21 May 2017 23:46:17 +0200</pubDate>
|
||||
|
||||
<guid>https://lettre.github.io/lettre/getting-started/intro/</guid>
|
||||
<description>Lettre is an email library that allows creating and sending messages. It provides:
|
||||
<description>This documentation is written for lettre 0.7, wich has not been released yet. Please use https://docs.rs/lettre/0.6.2/lettre/ for lettre 0.6.
|
||||
Lettre is an email library that allows creating and sending messages. It provides:
|
||||
An easy to use email builder Pluggable email transports Unicode support (for emails and transports, including for sender et recipient addresses when compatible) Secure defaults (emails are only sent encrypted by default) </description>
|
||||
</item>
|
||||
|
||||
@@ -51,7 +52,7 @@ The relay server can be the local email server, a specific host or a third-party
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/sendmail/</guid>
|
||||
<description>The sendmail transport sends the email using the local sendmail command.
|
||||
uselettre::sendmail::SendmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letmutsender =SendmailTransport::new(); letresult =sender.send(email); assert!(result.is_ok()); </description>
|
||||
use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&email); assert!(result.is_ok()); </description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -61,8 +62,7 @@ uselettre::sendmail::SendmailTransport; uselettre::{SimpleSendableEmail, EmailTr
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/file/</guid>
|
||||
<description>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.
|
||||
usestd::env::temp_dir; uselettre::file::FileEmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; // Write to the local temp directory letmutsender =FileEmailTransport::new(temp_dir()); letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letresult =sender.send(email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt:
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt; To: &lt;root@localhost&gt; From: &lt;user@localhost&gt; Subject: Hello Date: Sat, 31 Oct 2015 13:42:19 +0100 Message-ID: &lt;b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; // Write to the local temp directory let mut sender = FileEmailTransport::new(temp_dir()); let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let result = sender.send(&email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -72,8 +72,8 @@ b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&am
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/stub/</guid>
|
||||
<description>The stub transport only logs message envelope and drops the content. It can be useful for testing purposes.
|
||||
uselettre::stub::StubEmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letmutsender =StubEmailTransport; letresult =sender.send(email); assert!(result.is_ok()); Will log the line:
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt; </description>
|
||||
use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&email); assert!(result.is_ok()); Will log (when using a logger like env_logger):
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from= to= </description>
|
||||
</item>
|
||||
|
||||
</channel>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{
|
||||
"uri": "/content/getting-started/intro",
|
||||
"title": "Introduction",
|
||||
"content": "\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",
|
||||
"content": "\n{{% notice note %}}\nThis documentation is written for lettre 0.7, wich has not been released yet.\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": []
|
||||
},
|
||||
{
|
||||
@@ -26,7 +26,7 @@
|
||||
{
|
||||
"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};\n\n// Write to the local temp directory\nlet mut sender = FileEmailTransport::new(temp_dir());\nlet email = SimpleSendableEmail::new(\n \"user@localhost\",\n vec![\"root@localhost\"],\n \"message_id\",\n \"Hello world\"\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",
|
||||
"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": []
|
||||
},
|
||||
{
|
||||
@@ -38,19 +38,19 @@
|
||||
{
|
||||
"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};\n\nlet email = SimpleSendableEmail::new(\n \"user@localhost\",\n vec![\"root@localhost\"],\n \"message_id\",\n \"Hello world\"\n );\n\nlet mut sender = SendmailTransport::new();\nlet result = sender.send(email);\nassert!(result.is_ok());\n",
|
||||
"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};\nuse lettre::smtp::SmtpTransportBuilder;\nuse lettre::smtp::SecurityLevel;\n\nlet email = SimpleSendableEmail::new(\n \"user@localhost\",\n vec![\"root@localhost\"],\n \"message_id\",\n \"Hello world\"\n );\n\n// Open a local connection on port 25\nlet mut mailer =\nSmtpTransportBuilder::localhost().unwrap().security_level(SecurityLevel::Opportunistic).build();\n// Send the email\nlet result = mailer.send(email);\n\nassert!(result.is_ok());\n\n Complete example\n\nuse lettre::smtp::{SecurityLevel, SmtpTransport,\nSmtpTransportBuilder};\nuse lettre::smtp::authentication::Mechanism;\nuse lettre::smtp::SUBMISSION_PORT;\nuse lettre::{SimpleSendableEmail, EmailTransport};\n\nlet email = SimpleSendableEmail::new(\n \"user@localhost\",\n vec![\"root@localhost\"],\n \"message_id\",\n \"Hello world\"\n );\n\n// Connect to a remote server on a custom port\nlet mut mailer = SmtpTransportBuilder::new((\"server.tld\",\nSUBMISSION_PORT)).unwrap()\n // Set the name sent during EHLO/HELO, default is localhost\n .hello_name(\"my.hostname.tld\")\n // Add credentials for authentication\n .credentials(\"username\", \"password\")\n // Specify a TLS security level. You can also specify an SslContext with\n // .ssl_context(SslContext::Ssl23)\n .security_level(SecurityLevel::AlwaysEncrypt)\n // Enable SMTPUTF8 if the server supports it\n .smtp_utf8(true)\n // Configure expected authentication mechanism\n .authentication_mechanism(Mechanism::CramMd5)\n // Enable connection reuse\n .connection_reuse(true).build();\n\nlet result_1 = mailer.send(email.clone());\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::smtp::SMTP_PORT;\nuse lettre::smtp::client::Client;\nuse lettre::smtp::client::net::NetworkStream;\n\nlet mut email_client: ClientNetworkStream = Client::new();\nlet _ = emailclient.connect(&(\"localhost\", SMTPPORT), None);\nlet _ = emailclient.ehlo(\"myhostname\");\nlet _ = email_client.mail(\"user@example.com\", None);\nlet _ = email_client.rcpt(\"user@example.org\");\nlet _ = email_client.data();\nlet _ = email_client.message(\"Test email\");\nlet _ = email_client.quit();\n\n",
|
||||
"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};\n\nlet email = SimpleSendableEmail::new(\n \"user@localhost\",\n vec![\"root@localhost\"],\n \"message_id\",\n \"Hello world\"\n );\n\nlet mut sender = StubEmailTransport;\nlet result = sender.send(email);\nassert!(result.is_ok());\n\nWill log the line:\n\nb7c211bc-9811-45ce-8cd9-68eab575d695: from=user@localhost to=root@localhost\n`",
|
||||
"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": []
|
||||
}
|
||||
]
|
||||
@@ -271,34 +271,32 @@
|
||||
<p>The file transport writes the emails to the given directory. The name of the file will be
|
||||
<code>message_id.txt</code>.
|
||||
It can be useful for testing purposes, or if you want to keep track of sent messages.</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> std</span>::<span style="color: #f8f8f2">env</span>::<span style="color: #f8f8f2">temp_dir;</span>
|
||||
use std::env::temp_dir;
|
||||
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">file</span>::<span style="color: #f8f8f2">FileEmailTransport;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">{SimpleSendableEmail, EmailTransport};</span>
|
||||
use lettre::file::FileEmailTransport;
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color: #75715e">// Write to the local temp directory</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> sender </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> FileEmailTransport</span>::<span style="color: #f8f8f2">new(temp_dir());</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> email </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SimpleSendableEmail</span>::<span style="color: #f8f8f2">new(</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"user@localhost"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> vec</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">[</span><span style="color: #e6db74">"root@localhost"</span><span style="color: #f8f8f2">],</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"message_id"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"Hello world"</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2"> );</span>
|
||||
// Write to the local temp directory
|
||||
let mut sender = FileEmailTransport::new(temp_dir());
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"message_id".to_string(),
|
||||
"Hello world".to_string(),
|
||||
);
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> sender.send(email);</span>
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result.is_ok());</span>
|
||||
</pre></div>
|
||||
let result = sender.send(&email);
|
||||
assert!(result.is_ok());
|
||||
|
||||
<p>Example result in <code>/tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt</code>:</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span>b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
|
||||
To: <root@localhost>
|
||||
From: <user@localhost>
|
||||
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>
|
||||
Message-ID: <b7c211bc-9811-45ce-8cd9-68eab575d695.lettre@localhost>
|
||||
|
||||
Hello World!
|
||||
</pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ The relay server can be the local email server, a specific host or a third-party
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/sendmail/</guid>
|
||||
<description>The sendmail transport sends the email using the local sendmail command.
|
||||
uselettre::sendmail::SendmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letmutsender =SendmailTransport::new(); letresult =sender.send(email); assert!(result.is_ok()); </description>
|
||||
use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&email); assert!(result.is_ok()); </description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -51,8 +51,7 @@ uselettre::sendmail::SendmailTransport; uselettre::{SimpleSendableEmail, EmailTr
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/file/</guid>
|
||||
<description>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.
|
||||
usestd::env::temp_dir; uselettre::file::FileEmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; // Write to the local temp directory letmutsender =FileEmailTransport::new(temp_dir()); letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letresult =sender.send(email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt:
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt; To: &lt;root@localhost&gt; From: &lt;user@localhost&gt; Subject: Hello Date: Sat, 31 Oct 2015 13:42:19 +0100 Message-ID: &lt;b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; // Write to the local temp directory let mut sender = FileEmailTransport::new(temp_dir()); let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let result = sender.send(&email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -62,8 +61,8 @@ b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&am
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/stub/</guid>
|
||||
<description>The stub transport only logs message envelope and drops the content. It can be useful for testing purposes.
|
||||
uselettre::stub::StubEmailTransport; uselettre::{SimpleSendableEmail, EmailTransport}; letemail =SimpleSendableEmail::new( &quot;user@localhost&quot;, vec![&quot;root@localhost&quot;], &quot;message_id&quot;, &quot;Hello world&quot; ); letmutsender =StubEmailTransport; letresult =sender.send(email); assert!(result.is_ok()); Will log the line:
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt; </description>
|
||||
use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new("user@localhost".to_string()), vec![EmailAddress::new("root@localhost".to_string())], "message_id".to_string(), "Hello world".to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&email); assert!(result.is_ok()); Will log (when using a logger like env_logger):
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from= to= </description>
|
||||
</item>
|
||||
|
||||
</channel>
|
||||
|
||||
@@ -269,20 +269,19 @@
|
||||
|
||||
|
||||
<p>The sendmail transport sends the email using the local sendmail command.</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">sendmail</span>::<span style="color: #f8f8f2">SendmailTransport;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">{SimpleSendableEmail, EmailTransport};</span>
|
||||
use lettre::sendmail::SendmailTransport;
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> email </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SimpleSendableEmail</span>::<span style="color: #f8f8f2">new(</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"user@localhost"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> vec</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">[</span><span style="color: #e6db74">"root@localhost"</span><span style="color: #f8f8f2">],</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"message_id"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"Hello world"</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2"> );</span>
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"message_id".to_string(),
|
||||
"Hello world".to_string(),
|
||||
);
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> sender </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SendmailTransport</span>::<span style="color: #f8f8f2">new();</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> sender.send(email);</span>
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result.is_ok());</span>
|
||||
</pre></div>
|
||||
let mut sender = SendmailTransport::new();
|
||||
let result = sender.send(&email);
|
||||
assert!(result.is_ok());
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -303,85 +303,84 @@ emails directly to the destination.</p>
|
||||
<h4 id="simple-example">Simple example</h4>
|
||||
|
||||
<p>This is the most basic example of usage:</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">{SimpleSendableEmail, EmailTransport};</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">SmtpTransportBuilder;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">SecurityLevel;</span>
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> email </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SimpleSendableEmail</span>::<span style="color: #f8f8f2">new(</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"user@localhost"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> vec</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">[</span><span style="color: #e6db74">"root@localhost"</span><span style="color: #f8f8f2">],</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"message_id"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"Hello world"</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2"> );</span>
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"message_id".to_string(),
|
||||
"Hello world".to_string(),
|
||||
);
|
||||
|
||||
<span style="color: #75715e">// Open a local connection on port 25</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> mailer </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2">SmtpTransportBuilder</span>::<span style="color: #f8f8f2">localhost().unwrap().security_level(SecurityLevel</span>::<span style="color: #f8f8f2">Opportunistic).build();</span>
|
||||
<span style="color: #75715e">// Send the email</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> mailer.send(email);</span>
|
||||
// Open a local connection on port 25
|
||||
let mut mailer =
|
||||
SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
// Send the email
|
||||
let result = mailer.send(&email);
|
||||
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result.is_ok());</span>
|
||||
</pre></div>
|
||||
assert!(result.is_ok());
|
||||
|
||||
<h4 id="complete-example">Complete example</h4>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">{SecurityLevel, SmtpTransport,</span>
|
||||
<span style="color: #f8f8f2">SmtpTransportBuilder};</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">authentication</span>::<span style="color: #f8f8f2">Mechanism;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">SUBMISSION_PORT;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">{SimpleSendableEmail, EmailTransport};</span>
|
||||
use lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
use lettre::smtp::SUBMISSION_PORT;
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::ConnectionReuseParameters;
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> email </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SimpleSendableEmail</span>::<span style="color: #f8f8f2">new(</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"user@localhost"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> vec</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">[</span><span style="color: #e6db74">"root@localhost"</span><span style="color: #f8f8f2">],</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"message_id"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"Hello world"</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2"> );</span>
|
||||
|
||||
<span style="color: #75715e">// Connect to a remote server on a custom port</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> mailer </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SmtpTransportBuilder</span>::<span style="color: #f8f8f2">new((</span><span style="color: #e6db74">"server.tld"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2">SUBMISSION_PORT)).unwrap()</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Set the name sent during EHLO/HELO, default is `localhost`</span>
|
||||
<span style="color: #f8f8f2"> .hello_name(</span><span style="color: #e6db74">"my.hostname.tld"</span><span style="color: #f8f8f2">)</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Add credentials for authentication</span>
|
||||
<span style="color: #f8f8f2"> .credentials(</span><span style="color: #e6db74">"username"</span><span style="color: #f8f8f2">, </span><span style="color: #e6db74">"password"</span><span style="color: #f8f8f2">)</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Specify a TLS security level. You can also specify an SslContext with</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// .ssl_context(SslContext::Ssl23)</span>
|
||||
<span style="color: #f8f8f2"> .security_level(SecurityLevel</span>::<span style="color: #f8f8f2">AlwaysEncrypt)</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Enable SMTPUTF8 if the server supports it</span>
|
||||
<span style="color: #f8f8f2"> .smtp_utf8(</span><span style="color: #66d9ef">true</span><span style="color: #f8f8f2">)</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Configure expected authentication mechanism</span>
|
||||
<span style="color: #f8f8f2"> .authentication_mechanism(Mechanism</span>::<span style="color: #f8f8f2">CramMd5)</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #75715e">// Enable connection reuse</span>
|
||||
<span style="color: #f8f8f2"> .connection_reuse(</span><span style="color: #66d9ef">true</span><span style="color: #f8f8f2">).build();</span>
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"message_id".to_string(),
|
||||
"Hello world".to_string(),
|
||||
);
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result_1 </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> mailer.send(email.clone());</span>
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result_1.is_ok());</span>
|
||||
// Connect to a remote server on a custom port
|
||||
let mut mailer = SmtpTransport::simple_builder("server.tld".to_string()).unwrap()
|
||||
// Set the name sent during EHLO/HELO, default is `localhost`
|
||||
.hello_name(ClientId::Domain("my.hostname.tld".to_string()))
|
||||
// Add credentials for authentication
|
||||
.credentials(Credentials::new("username".to_string(), "password".to_string()))
|
||||
// Enable SMTPUTF8 if the server supports it
|
||||
.smtp_utf8(true)
|
||||
// Configure expected authentication mechanism
|
||||
.authentication_mechanism(Mechanism::Plain)
|
||||
// Enable connection reuse
|
||||
.connection_reuse(ConnectionReuseParameters::ReuseUnlimited).build();
|
||||
|
||||
<span style="color: #75715e">// The second email will use the same connection</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result_2 </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> mailer.send(email);</span>
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result_2.is_ok());</span>
|
||||
let result_1 = mailer.send(&email);
|
||||
assert!(result_1.is_ok());
|
||||
|
||||
<span style="color: #75715e">// Explicitly close the SMTP transaction as we enabled connection reuse</span>
|
||||
<span style="color: #f8f8f2">mailer.close();</span>
|
||||
</pre></div>
|
||||
// The second email will use the same connection
|
||||
let result_2 = mailer.send(&email);
|
||||
assert!(result_2.is_ok());
|
||||
|
||||
// Explicitly close the SMTP transaction as we enabled connection reuse
|
||||
mailer.close();
|
||||
|
||||
<h4 id="lower-level">Lower level</h4>
|
||||
|
||||
<p>You can also send commands, here is a simple email transaction without
|
||||
error handling:</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">SMTP_PORT;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">client</span>::<span style="color: #f8f8f2">Client;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">smtp</span>::<span style="color: #f8f8f2">client</span>::<span style="color: #f8f8f2">net</span>::<span style="color: #f8f8f2">NetworkStream;</span>
|
||||
use lettre::EmailAddress;
|
||||
use lettre::smtp::SMTP_PORT;
|
||||
use lettre::smtp::client::Client;
|
||||
use lettre::smtp::client::net::NetworkStream;
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::commands::*;
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> email_client</span>: <span style="color: #a6e22e">Client</span><span style="color: #f92672"><</span><span style="color: #f8f8f2">NetworkStream</span><span style="color: #f92672">></span><span style="color: #f8f8f2"> </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> Client</span>::<span style="color: #f8f8f2">new();</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.connect(</span><span style="color: #f92672">&</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">"localhost"</span><span style="color: #f8f8f2">, SMTP_PORT), None);</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.ehlo(</span><span style="color: #e6db74">"my_hostname"</span><span style="color: #f8f8f2">);</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.mail(</span><span style="color: #e6db74">"user@example.com"</span><span style="color: #f8f8f2">, None);</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.rcpt(</span><span style="color: #e6db74">"user@example.org"</span><span style="color: #f8f8f2">);</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.data();</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.message(</span><span style="color: #e6db74">"Test email"</span><span style="color: #f8f8f2">);</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> _ </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> email_client.quit();</span>
|
||||
</pre></div>
|
||||
let mut email_client: Client<NetworkStream> = Client::new();
|
||||
let _ = email_client.connect(&("localhost", SMTP_PORT), None);
|
||||
let _ = email_client.smtp_command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
|
||||
let _ = email_client.smtp_command(
|
||||
MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
|
||||
);
|
||||
let _ = email_client.smtp_command(
|
||||
RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
|
||||
);
|
||||
let _ = email_client.smtp_command(DataCommand);
|
||||
let _ = email_client.message(Box::new("Test email".as_bytes()));
|
||||
let _ = email_client.smtp_command(QuitCommand);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -270,24 +270,22 @@
|
||||
|
||||
<p>The stub transport only logs message envelope and drops the content. It can be useful for
|
||||
testing purposes.</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span><span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">stub</span>::<span style="color: #f8f8f2">StubEmailTransport;</span>
|
||||
<span style="color: #66d9ef">use</span><span style="color: #f8f8f2"> lettre</span>::<span style="color: #f8f8f2">{SimpleSendableEmail, EmailTransport};</span>
|
||||
use lettre::stub::StubEmailTransport;
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> email </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> SimpleSendableEmail</span>::<span style="color: #f8f8f2">new(</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"user@localhost"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> vec</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">[</span><span style="color: #e6db74">"root@localhost"</span><span style="color: #f8f8f2">],</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"message_id"</span><span style="color: #f8f8f2">,</span>
|
||||
<span style="color: #f8f8f2"> </span><span style="color: #e6db74">"Hello world"</span><span style="color: #f8f8f2"></span>
|
||||
<span style="color: #f8f8f2"> );</span>
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"message_id".to_string(),
|
||||
"Hello world".to_string(),
|
||||
);
|
||||
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> </span><span style="color: #66d9ef">mut</span><span style="color: #f8f8f2"> sender </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> StubEmailTransport;</span>
|
||||
<span style="color: #66d9ef">let</span><span style="color: #f8f8f2"> result </span><span style="color: #f92672">=</span><span style="color: #f8f8f2"> sender.send(email);</span>
|
||||
<span style="color: #f8f8f2">assert</span><span style="color: #f92672">!</span><span style="color: #f8f8f2">(result.is_ok());</span>
|
||||
</pre></div>
|
||||
let mut sender = StubEmailTransport::new_positive();
|
||||
let result = sender.send(&email);
|
||||
assert!(result.is_ok());
|
||||
|
||||
<p>Will log the line:</p>
|
||||
<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span></span>b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
|
||||
</pre></div>
|
||||
<p>Will log (when using a logger like <code>env_logger</code>):</p>
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user