feat(all): Move doc to website and test it
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
.vscode/
|
||||
.project
|
||||
.project/
|
||||
.idea/
|
||||
lettre.iml
|
||||
target/
|
||||
/Cargo.lock
|
||||
|
||||
@@ -29,10 +29,5 @@ before_script:
|
||||
- sudo chgrp -R postdrop /var/spool/postfix/maildrop
|
||||
|
||||
script:
|
||||
- cargo test --verbose --manifest-path lettre/Cargo.toml --no-default-features
|
||||
- cargo test --verbose --manifest-path lettre/Cargo.toml
|
||||
- cargo test --verbose --manifest-path lettre_email/Cargo.toml
|
||||
- cargo test --verbose --all
|
||||
|
||||
env:
|
||||
global:
|
||||
secure: "MaZ3TzuaAHuxmxQkfJdqRfkh7/ieScJRk0T/2yjysZhDMTYyRmp5wh/zkfW1ADuG0uc4Pqsxrsh1J9SVO7O0U5NJA8NKZi/pgiL+FHh0g4YtlHxy2xmFNB5am3Kyc+E7B4XylwTbA9S8ublVM0nvX7yX/a5fbwEUInVk2bA8fpc="
|
||||
|
||||
37
README.md
37
README.md
@@ -22,6 +22,43 @@ Lettre provides the following features:
|
||||
See https://github.com/lettre/lettre/blob/master/lettre_email/examples/smtp.rs
|
||||
for a simple example of how to build and send an email.
|
||||
|
||||
```rust,no_run
|
||||
extern crate lettre;
|
||||
extern crate lettre_email;
|
||||
extern crate mime;
|
||||
|
||||
use lettre::{EmailTransport, SmtpTransport};
|
||||
use lettre_email::EmailBuilder;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let email = EmailBuilder::new()
|
||||
// Addresses can be specified by the tuple (email, alias)
|
||||
.to(("user@example.org", "Firstname Lastname"))
|
||||
// ... or by an address only
|
||||
.from("user@example.com")
|
||||
.subject("Hi, Hello world")
|
||||
.text("Hello world.")
|
||||
.attachment(Path::new("Cargo.toml"), None, &mime::TEXT_PLAIN).unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer = SmtpTransport::builder_unencrypted_localhost().unwrap()
|
||||
.build();
|
||||
// Send the email
|
||||
let result = mailer.send(&email);
|
||||
|
||||
if result.is_ok() {
|
||||
println!("Email sent");
|
||||
} else {
|
||||
println!("Could not send email: {:?}", result);
|
||||
}
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Released versions:
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
<title>404 Page not found</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/horsey.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/horsey.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left {
|
||||
|
||||
693
docs/creating-messages/email/index.html
Normal file
693
docs/creating-messages/email/index.html
Normal file
@@ -0,0 +1,693 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="js csstransforms3d">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<meta name="generator" content="Hugo 0.32.4" />
|
||||
<meta name="description" content="Documentation for the Lettre mailer in Rust">
|
||||
<meta name="author" content="Alexis Mousset">
|
||||
|
||||
<link rel="shortcut icon" href="https://lettre.github.io/lettre/images/favicon.png" type="image/x-icon" />
|
||||
|
||||
<title>Email creation :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
display:none !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body class="" data-url="/lettre/creating-messages/email/">
|
||||
<nav id="sidebar" class="">
|
||||
|
||||
|
||||
|
||||
<div id="header-wrapper">
|
||||
<div id="header">
|
||||
<a href="https://lettre.github.io/lettre/getting-started/intro/"><img src="https://lettre.github.io/lettre/images/logo50.png" /></a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="searchbox">
|
||||
<label for="search-by"><i class="fa fa-search"></i></label>
|
||||
<input data-search-input id="search-by" type="text" placeholder="Search...">
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="highlightable">
|
||||
<ul class="topics">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/getting-started/" title="Getting started" class="dd-item
|
||||
|
||||
|
||||
|
||||
">
|
||||
<a href="/lettre/getting-started/">
|
||||
Getting started
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/getting-started/intro/" title="Introduction" class="dd-item ">
|
||||
<a href="/lettre/getting-started/intro/">
|
||||
Introduction
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/" title="Creating messages" class="dd-item
|
||||
parent
|
||||
|
||||
|
||||
">
|
||||
<a href="/lettre/creating-messages/">
|
||||
Creating messages
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item active">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/" title="Sending messages" class="dd-item
|
||||
|
||||
|
||||
|
||||
">
|
||||
<a href="/lettre/sending-messages/">
|
||||
Sending messages
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/intro/" title="Introduction" class="dd-item ">
|
||||
<a href="/lettre/sending-messages/intro/">
|
||||
Introduction
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/smtp/" title="SMTP transport" class="dd-item ">
|
||||
<a href="/lettre/sending-messages/smtp/">
|
||||
SMTP transport
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/sendmail/" title="Sendmail transport" class="dd-item ">
|
||||
<a href="/lettre/sending-messages/sendmail/">
|
||||
Sendmail transport
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/file/" title="File transport" class="dd-item ">
|
||||
<a href="/lettre/sending-messages/file/">
|
||||
File transport
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/sending-messages/stub/" title="Stub transport" class="dd-item ">
|
||||
<a href="/lettre/sending-messages/stub/">
|
||||
Stub transport
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="footer">
|
||||
<p>Built with <a href="https://github.com/matcornic/hugo-theme-learn"><i class="fa fa-heart"></i></a> from <a href="http://getgrav.org">Grav</a> and <a href="http://gohugo.io/">Hugo</a></p>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="body">
|
||||
<div id="overlay"></div>
|
||||
<div class="padding highlightable sticky-parent">
|
||||
|
||||
<div class="sticky-spacer">
|
||||
<div id="top-bar">
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="top-github-link">
|
||||
<a class="github-link" href="https://github.com/lettre/lettre/edit/master/website/content/creating-messages/email.md" target="blank">
|
||||
<i class="fa fa-code-fork"></i>
|
||||
Edit this page
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="breadcrumbs" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb">
|
||||
<span id="sidebar-toggle-span">
|
||||
<a href="#" id="sidebar-toggle" data-sidebar-toggle="">
|
||||
<i class="fa fa-bars"></i>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span id="toc-menu"><i class="fa fa-list-alt"></i></span>
|
||||
|
||||
<span class="links">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href='/lettre/'>Lettre site</a> > <a href='/lettre/creating-messages/'>Creating messages</a> > Email creation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="progress">
|
||||
<div class="wrapper">
|
||||
<nav id="TableOfContents">
|
||||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<li><a href="#simple-example">Simple example</a></li>
|
||||
<li><a href="#complete-example">Complete example</a></li>
|
||||
</ul></li>
|
||||
</ul></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="body-inner">
|
||||
|
||||
<h1>Email creation</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 id="simple-example">Simple example</h4>
|
||||
|
||||
<p>The <code>email</code> part builds email messages. For now, it does not support attachments.
|
||||
An email is built using an <code>EmailBuilder</code>. The simplest email could be:</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">crate</span> lettre_email;
|
||||
|
||||
<span style="color:#66d9ef">use</span> lettre_email::EmailBuilder;
|
||||
|
||||
<span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">main</span>() {
|
||||
<span style="color:#75715e">// Create an email
|
||||
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> EmailBuilder::new()
|
||||
<span style="color:#75715e">// Addresses can be specified by the tuple (email, alias)
|
||||
</span><span style="color:#75715e"></span> .to((<span style="color:#e6db74">"user@example.org"</span>, <span style="color:#e6db74">"Firstname Lastname"</span>))
|
||||
<span style="color:#75715e">// ... or by an address only
|
||||
</span><span style="color:#75715e"></span> .from(<span style="color:#e6db74">"user@example.com"</span>)
|
||||
.subject(<span style="color:#e6db74">"Hi, Hello world"</span>)
|
||||
.text(<span style="color:#e6db74">"Hello world."</span>)
|
||||
.build();
|
||||
|
||||
assert<span style="color:#f92672">!</span>(email.is_ok());
|
||||
}</code></pre></div>
|
||||
<p>When the <code>build</code> method is called, the <code>EmailBuilder</code> will add the missing headers (like
|
||||
<code>Message-ID</code> or <code>Date</code>) and check for missing necessary ones (like <code>From</code> or <code>To</code>). It will
|
||||
then generate an <code>Email</code> that can be sent.</p>
|
||||
|
||||
<p>The <code>text()</code> method will create a plain text email, while the <code>html()</code> method will create an
|
||||
HTML email. You can use the <code>alternative()</code> method to provide both versions, using plain text
|
||||
as fallback for the HTML version.</p>
|
||||
|
||||
<h4 id="complete-example">Complete example</h4>
|
||||
|
||||
<p>Below is a more complete example, not using method chaining:</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">crate</span> lettre_email;
|
||||
|
||||
<span style="color:#66d9ef">use</span> lettre_email::EmailBuilder;
|
||||
|
||||
<span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">main</span>() {
|
||||
<span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> builder <span style="color:#f92672">=</span> EmailBuilder::new();
|
||||
builder.add_to((<span style="color:#e6db74">"user@example.org"</span>, <span style="color:#e6db74">"Alias name"</span>));
|
||||
builder.add_cc((<span style="color:#e6db74">"user@example.net"</span>, <span style="color:#e6db74">"Alias name"</span>));
|
||||
builder.add_from(<span style="color:#e6db74">"no-reply@example.com"</span>);
|
||||
builder.add_from(<span style="color:#e6db74">"no-reply@example.eu"</span>);
|
||||
builder.set_sender(<span style="color:#e6db74">"no-reply@example.com"</span>);
|
||||
builder.set_subject(<span style="color:#e6db74">"Hello world"</span>);
|
||||
builder.set_alternative(<span style="color:#e6db74">"<h2>Hi, Hello world.</h2>"</span>, <span style="color:#e6db74">"Hi, Hello world."</span>);
|
||||
builder.add_reply_to(<span style="color:#e6db74">"contact@example.com"</span>);
|
||||
builder.add_header((<span style="color:#e6db74">"X-Custom-Header"</span>, <span style="color:#e6db74">"my header"</span>));
|
||||
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> builder.build();
|
||||
assert<span style="color:#f92672">!</span>(email.is_ok());
|
||||
}</code></pre></div>
|
||||
<p>See the <code>EmailBuilder</code> documentation for a complete list of methods.</p>
|
||||
|
||||
|
||||
<footer class=" footline" >
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="navigation">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a class="nav nav-prev" href="/lettre/creating-messages/" title="Creating messages"> <i class="fa fa-chevron-left"></i></a>
|
||||
|
||||
|
||||
<a class="nav nav-next" href="/lettre/sending-messages/" title="Sending messages" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Creating messages :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -362,7 +391,7 @@
|
||||
|
||||
<h3 id="creating-messages">Creating messages</h3>
|
||||
|
||||
<p>The documentation for the <code>lettre_email</code> is available on <a href="https://docs.rs/lettre_email/0.7.0/lettre_email/">https://docs.rs/lettre_email/0.7.0/lettre_email/</a> for now.</p>
|
||||
<p>This section explains how to create emails.</p>
|
||||
|
||||
|
||||
<footer class=" footline" >
|
||||
@@ -442,9 +471,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -461,6 +487,25 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -554,7 +599,7 @@
|
||||
<a class="nav nav-prev" href="/lettre/getting-started/intro/" title="Introduction"> <i class="fa fa-chevron-left"></i></a>
|
||||
|
||||
|
||||
<a class="nav nav-next" href="/lettre/sending-messages/" title="Sending messages" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
||||
<a class="nav nav-next" href="/lettre/creating-messages/email/" title="Email creation" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -563,20 +608,20 @@
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -11,5 +11,15 @@
|
||||
<atom:link href="https://lettre.github.io/lettre/creating-messages/index.xml" rel="self" type="application/rss+xml" />
|
||||
|
||||
|
||||
<item>
|
||||
<title>Email creation</title>
|
||||
<link>https://lettre.github.io/lettre/creating-messages/email/</link>
|
||||
<pubDate>Sun, 21 Jan 2018 23:46:17 +0200</pubDate>
|
||||
|
||||
<guid>https://lettre.github.io/lettre/creating-messages/email/</guid>
|
||||
<description>Simple example The email part builds email messages. For now, it does not support attachments. An email is built using an EmailBuilder. The simplest email could be:
|
||||
extern crate lettre_email; use lettre_email::EmailBuilder; fn main() { // Create an email let email = EmailBuilder::new() // Addresses can be specified by the tuple (email, alias) .to((&#34;user@example.org&#34;, &#34;Firstname Lastname&#34;)) // ... or by an address only .from(&#34;user@example.com&#34;) .subject(&#34;Hi, Hello world&#34;) .</description>
|
||||
</item>
|
||||
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Getting started :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -442,6 +471,22 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -560,20 +605,20 @@
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Introduction :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -448,6 +477,22 @@ Please use <a href="https://docs.rs/lettre/0.6.2/lettre/">https://docs.rs/lettre
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -566,20 +611,20 @@ Please use <a href="https://docs.rs/lettre/0.6.2/lettre/">https://docs.rs/lettre
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
{
|
||||
"uri": "/content/creating-messages/_index",
|
||||
"title": "Creating messages",
|
||||
"content": "\nCreating messages\n\nThe documentation for the lettreemail is available on https://docs.rs/lettreemail/0.7.0/lettre_email/ for now.\n\n",
|
||||
"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": []
|
||||
},
|
||||
{
|
||||
@@ -26,31 +32,31 @@
|
||||
{
|
||||
"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",
|
||||
"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, EmailAddress};\n\nfn main() {\n // Write to the local temp directory\n let mut sender = FileEmailTransport::new(temp_dir());\n let 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 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 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",
|
||||
"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\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",
|
||||
"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, EmailAddress};\n\nfn main() {\n let 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 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 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.command(EhloCommand::new(ClientId::new(\"myhostname\".to_string())));\nlet _ = email_client.command(\n MailCommand::new(Some(EmailAddress::new(\"user@example.com\".to_string())), vec![])\n );\nlet _ = email_client.command(\n RcptCommand::new(EmailAddress::new(\"user@example.org\".to_string()), vec![])\n );\nlet _ = email_client.command(DataCommand);\nlet _ = emailclient.message(Box::new(\"Test email\".asbytes()));\nlet _ = email_client.command(QuitCommand);\n\n",
|
||||
"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, EmailAddress, SmtpTransport};\n\nfn main() {\n let 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\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, EmailAddress, SmtpTransport};\nuse lettre::smtp::extension::ClientId;\nuse lettre::smtp::ConnectionReuseParameters;\n\nfn main() {\n let 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\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())), vec![])\n );\n let _ = email_client.command(\n RcptCommand::new(EmailAddress::new(\"user@example.org\".to_string()), 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\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",
|
||||
"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, EmailAddress};\n\nfn main() {\n let 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 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": []
|
||||
}
|
||||
]
|
||||
@@ -30,7 +30,7 @@
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/intro/</guid>
|
||||
<description>This mailer contains several different transports for your emails. To be sendable, the emails have to implement SendableEmail, which is the case for emails created with lettre_email.
|
||||
The following transports are available:
|
||||
The SmtpTransport uses the SMTP protocol to send the message over the network. It is the prefered way of sending emails. The SendmailTransport uses the sendmail command to send messages. It is an alternative to the SMTP transport.</description>
|
||||
The SmtpTransport uses the SMTP protocol to send the message over the network. It is the preferred way of sending emails. The SendmailTransport uses the sendmail command to send messages. It is an alternative to the SMTP transport.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -40,8 +40,8 @@ The following transports are available:
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/smtp/</guid>
|
||||
<description>This transport uses the SMTP protocol to send emails over the network (locally or remotely).
|
||||
It is desinged to be:
|
||||
Secured: email are encrypted by default Modern: Unicode support for email content and sender/recipient adresses when compatible Fast: supports tcp connection reuse This client is designed to send emails to a relay server, and should not be used to send emails directly to the destination.
|
||||
It is designed to be:
|
||||
Secured: email are encrypted by default Modern: Unicode support for email content and sender/recipient addresses when compatible Fast: supports tcp connection reuse This client is designed to send emails to a relay server, and should not be used to send emails directly to the destination.
|
||||
The relay server can be the local email server, a specific host or a third-party service.</description>
|
||||
</item>
|
||||
|
||||
@@ -52,7 +52,17 @@ 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.
|
||||
use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&amp;email); assert!</description>
|
||||
extern crate lettre; use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&amp;email); assert!(result.is_ok()); }</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Email creation</title>
|
||||
<link>https://lettre.github.io/lettre/creating-messages/email/</link>
|
||||
<pubDate>Sun, 21 Jan 2018 23:46:17 +0200</pubDate>
|
||||
|
||||
<guid>https://lettre.github.io/lettre/creating-messages/email/</guid>
|
||||
<description>Simple example The email part builds email messages. For now, it does not support attachments. An email is built using an EmailBuilder. The simplest email could be:
|
||||
extern crate lettre_email; use lettre_email::EmailBuilder; fn main() { // Create an email let email = EmailBuilder::new() // Addresses can be specified by the tuple (email, alias) .to((&#34;user@example.org&#34;, &#34;Firstname Lastname&#34;)) // ... or by an address only .from(&#34;user@example.com&#34;) .subject(&#34;Hi, Hello world&#34;) .</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -62,7 +72,7 @@ use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, Email
|
||||
|
||||
<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.
|
||||
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(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let result = sender.send(&amp;email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
extern crate lettre; use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { // Write to the local temp directory let mut sender = FileEmailTransport::new(temp_dir()); let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -72,7 +82,7 @@ use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{Simpl
|
||||
|
||||
<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.
|
||||
use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&amp;email); assert!(result.is_ok()); Will log (when using a logger like env_logger):
|
||||
extern crate lettre; use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&amp;email); assert!(result.is_ok()); } Will log (when using a logger like env_logger):
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt;</description>
|
||||
</item>
|
||||
|
||||
|
||||
56
docs/json/search.json
Normal file
56
docs/json/search.json
Normal file
@@ -0,0 +1,56 @@
|
||||
[
|
||||
{
|
||||
"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": "\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};\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",
|
||||
"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};\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",
|
||||
"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",
|
||||
"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`",
|
||||
"tags": []
|
||||
}
|
||||
]
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>File transport :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -357,22 +386,26 @@
|
||||
<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"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> std::env::temp_dir;
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">crate</span> lettre;
|
||||
|
||||
<span style="color:#66d9ef">use</span> std::env::temp_dir;
|
||||
|
||||
<span style="color:#66d9ef">use</span> lettre::file::FileEmailTransport;
|
||||
<span style="color:#66d9ef">use</span> lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color:#75715e">// Write to the local temp directory
|
||||
</span><span style="color:#75715e"></span><span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> sender <span style="color:#f92672">=</span> FileEmailTransport::new(temp_dir());
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
|
||||
<span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> sender.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
<span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">main</span>() {
|
||||
<span style="color:#75715e">// Write to the local temp directory
|
||||
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> sender <span style="color:#f92672">=</span> FileEmailTransport::new(temp_dir());
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
|
||||
<span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> sender.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());
|
||||
}</code></pre></div>
|
||||
<p>Example result in <code>/tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.txt</code>:</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
|
||||
To: <root@localhost>
|
||||
@@ -460,6 +493,22 @@ Hello World!</code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -586,20 +635,20 @@ Hello World!</code></pre></div>
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Sending messages :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -441,6 +470,22 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -551,7 +596,7 @@
|
||||
|
||||
|
||||
|
||||
<a class="nav nav-prev" href="/lettre/creating-messages/" title="Creating messages"> <i class="fa fa-chevron-left"></i></a>
|
||||
<a class="nav nav-prev" href="/lettre/creating-messages/email/" title="Email creation"> <i class="fa fa-chevron-left"></i></a>
|
||||
|
||||
|
||||
<a class="nav nav-next" href="/lettre/sending-messages/intro/" title="Introduction" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
||||
@@ -563,20 +608,20 @@
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/intro/</guid>
|
||||
<description>This mailer contains several different transports for your emails. To be sendable, the emails have to implement SendableEmail, which is the case for emails created with lettre_email.
|
||||
The following transports are available:
|
||||
The SmtpTransport uses the SMTP protocol to send the message over the network. It is the prefered way of sending emails. The SendmailTransport uses the sendmail command to send messages. It is an alternative to the SMTP transport.</description>
|
||||
The SmtpTransport uses the SMTP protocol to send the message over the network. It is the preferred way of sending emails. The SendmailTransport uses the sendmail command to send messages. It is an alternative to the SMTP transport.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -29,8 +29,8 @@ The following transports are available:
|
||||
|
||||
<guid>https://lettre.github.io/lettre/sending-messages/smtp/</guid>
|
||||
<description>This transport uses the SMTP protocol to send emails over the network (locally or remotely).
|
||||
It is desinged to be:
|
||||
Secured: email are encrypted by default Modern: Unicode support for email content and sender/recipient adresses when compatible Fast: supports tcp connection reuse This client is designed to send emails to a relay server, and should not be used to send emails directly to the destination.
|
||||
It is designed to be:
|
||||
Secured: email are encrypted by default Modern: Unicode support for email content and sender/recipient addresses when compatible Fast: supports tcp connection reuse This client is designed to send emails to a relay server, and should not be used to send emails directly to the destination.
|
||||
The relay server can be the local email server, a specific host or a third-party service.</description>
|
||||
</item>
|
||||
|
||||
@@ -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.
|
||||
use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&amp;email); assert!</description>
|
||||
extern crate lettre; use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = SendmailTransport::new(); let result = sender.send(&amp;email); assert!(result.is_ok()); }</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -51,7 +51,7 @@ use lettre::sendmail::SendmailTransport; use lettre::{SimpleSendableEmail, Email
|
||||
|
||||
<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.
|
||||
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(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let result = sender.send(&amp;email); assert!(result.is_ok()); Example result in /tmp/b7c211bc-9811-45ce-8cd9-68eab575d695.</description>
|
||||
extern crate lettre; use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { // Write to the local temp directory let mut sender = FileEmailTransport::new(temp_dir()); let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
@@ -61,7 +61,7 @@ use std::env::temp_dir; use lettre::file::FileEmailTransport; use lettre::{Simpl
|
||||
|
||||
<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.
|
||||
use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&amp;email); assert!(result.is_ok()); Will log (when using a logger like env_logger):
|
||||
extern crate lettre; use lettre::stub::StubEmailTransport; use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress}; fn main() { let email = SimpleSendableEmail::new( EmailAddress::new(&#34;user@localhost&#34;.to_string()), vec![EmailAddress::new(&#34;root@localhost&#34;.to_string())], &#34;message_id&#34;.to_string(), &#34;Hello world&#34;.to_string(), ); let mut sender = StubEmailTransport::new_positive(); let result = sender.send(&amp;email); assert!(result.is_ok()); } Will log (when using a logger like env_logger):
|
||||
b7c211bc-9811-45ce-8cd9-68eab575d695: from=&lt;user@localhost&gt; to=&lt;root@localhost&gt;</description>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Introduction :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -361,7 +390,7 @@ emails have to implement <code>SendableEmail</code>, which is the case for email
|
||||
|
||||
<ul>
|
||||
<li>The <code>SmtpTransport</code> uses the SMTP protocol to send the message over the network. It is
|
||||
the prefered way of sending emails.</li>
|
||||
the preferred way of sending emails.</li>
|
||||
<li>The <code>SendmailTransport</code> uses the sendmail command to send messages. It is an alternative to
|
||||
the SMTP transport.</li>
|
||||
<li>The <code>FileTransport</code> creates a file containing the email content to be sent. It can be used
|
||||
@@ -448,6 +477,22 @@ logs.</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -571,20 +616,20 @@ logs.</li>
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Sendmail transport :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -355,19 +384,23 @@
|
||||
|
||||
|
||||
<p>The sendmail transport sends the email using the local sendmail command.</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> lettre::sendmail::SendmailTransport;
|
||||
<span style="color:#66d9ef">use</span> lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust,no_run" data-lang="rust,no_run">extern crate lettre;
|
||||
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
use lettre::sendmail::SendmailTransport;
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> sender <span style="color:#f92672">=</span> SendmailTransport::new();
|
||||
<span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> sender.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
fn main() {
|
||||
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());
|
||||
}</code></pre></div>
|
||||
|
||||
<footer class=" footline" >
|
||||
|
||||
@@ -446,6 +479,22 @@ assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -572,20 +621,20 @@ assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>SMTP transport :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -373,11 +402,11 @@
|
||||
|
||||
<p>This transport uses the SMTP protocol to send emails over the network (locally or remotely).</p>
|
||||
|
||||
<p>It is desinged to be:</p>
|
||||
<p>It is designed to be:</p>
|
||||
|
||||
<ul>
|
||||
<li>Secured: email are encrypted by default</li>
|
||||
<li>Modern: Unicode support for email content and sender/recipient adresses when compatible</li>
|
||||
<li>Modern: Unicode support for email content and sender/recipient addresses when compatible</li>
|
||||
<li>Fast: supports tcp connection reuse</li>
|
||||
</ul>
|
||||
|
||||
@@ -389,82 +418,92 @@ 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"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust,no_run" data-lang="rust,no_run">extern crate lettre;
|
||||
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
|
||||
<span style="color:#75715e">// Open a local connection on port 25
|
||||
</span><span style="color:#75715e"></span><span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> mailer <span style="color:#f92672">=</span>
|
||||
SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
<span style="color:#75715e">// Send the email
|
||||
</span><span style="color:#75715e"></span><span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> mailer.send(<span style="color:#f92672">&</span>email);
|
||||
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
fn main() {
|
||||
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(),
|
||||
);
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer =
|
||||
SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
// Send the email
|
||||
let result = mailer.send(&email);
|
||||
|
||||
assert!(result.is_ok());
|
||||
}</code></pre></div>
|
||||
<h4 id="complete-example">Complete example</h4>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::SUBMISSION_PORT;
|
||||
<span style="color:#66d9ef">use</span> lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::extension::ClientId;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::ConnectionReuseParameters;
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust,no_run" data-lang="rust,no_run">extern crate lettre;
|
||||
|
||||
use lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::ConnectionReuseParameters;
|
||||
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
|
||||
<span style="color:#75715e">// Connect to a remote server on a custom port
|
||||
</span><span style="color:#75715e"></span><span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> mailer <span style="color:#f92672">=</span> SmtpTransport::simple_builder(<span style="color:#e6db74">"server.tld"</span>.to_string()).unwrap()
|
||||
<span style="color:#75715e">// Set the name sent during EHLO/HELO, default is `localhost`
|
||||
</span><span style="color:#75715e"></span> .hello_name(ClientId::Domain(<span style="color:#e6db74">"my.hostname.tld"</span>.to_string()))
|
||||
<span style="color:#75715e">// Add credentials for authentication
|
||||
</span><span style="color:#75715e"></span> .credentials(Credentials::new(<span style="color:#e6db74">"username"</span>.to_string(), <span style="color:#e6db74">"password"</span>.to_string()))
|
||||
<span style="color:#75715e">// Enable SMTPUTF8 if the server supports it
|
||||
</span><span style="color:#75715e"></span> .smtp_utf8(<span style="color:#66d9ef">true</span>)
|
||||
<span style="color:#75715e">// Configure expected authentication mechanism
|
||||
</span><span style="color:#75715e"></span> .authentication_mechanism(Mechanism::Plain)
|
||||
<span style="color:#75715e">// Enable connection reuse
|
||||
</span><span style="color:#75715e"></span> .connection_reuse(ConnectionReuseParameters::ReuseUnlimited).build();
|
||||
|
||||
<span style="color:#66d9ef">let</span> result_1 <span style="color:#f92672">=</span> mailer.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result_1.is_ok());
|
||||
|
||||
<span style="color:#75715e">// The second email will use the same connection
|
||||
</span><span style="color:#75715e"></span><span style="color:#66d9ef">let</span> result_2 <span style="color:#f92672">=</span> mailer.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result_2.is_ok());
|
||||
|
||||
<span style="color:#75715e">// Explicitly close the SMTP transaction as we enabled connection reuse
|
||||
</span><span style="color:#75715e"></span>mailer.close();</code></pre></div>
|
||||
fn main() {
|
||||
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(),
|
||||
);
|
||||
|
||||
// Connect to a remote server on a custom port
|
||||
let mut mailer = SmtpTransport::simple_builder("server.tld").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();
|
||||
|
||||
let result_1 = mailer.send(&email);
|
||||
assert!(result_1.is_ok());
|
||||
|
||||
// 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();
|
||||
}</code></pre></div>
|
||||
<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"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> lettre::EmailAddress;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::SMTP_PORT;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::client::Client;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::client::net::NetworkStream;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::extension::ClientId;
|
||||
<span style="color:#66d9ef">use</span> lettre::smtp::commands::<span style="color:#f92672">*</span>;
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust,no_run" data-lang="rust,no_run">extern crate lettre;
|
||||
|
||||
<span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> email_client: <span style="color:#a6e22e">Client</span><span style="color:#f92672"><</span>NetworkStream<span style="color:#f92672">></span> <span style="color:#f92672">=</span> Client::new();
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.connect(<span style="color:#f92672">&</span>(<span style="color:#e6db74">"localhost"</span>, SMTP_PORT), None);
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.command(EhloCommand::new(ClientId::new(<span style="color:#e6db74">"my_hostname"</span>.to_string())));
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.command(
|
||||
MailCommand::new(Some(EmailAddress::new(<span style="color:#e6db74">"user@example.com"</span>.to_string())), vec<span style="color:#f92672">!</span>[])
|
||||
);
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.command(
|
||||
RcptCommand::new(EmailAddress::new(<span style="color:#e6db74">"user@example.org"</span>.to_string()), vec<span style="color:#f92672">!</span>[])
|
||||
);
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.command(DataCommand);
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.message(Box::new(<span style="color:#e6db74">"Test email"</span>.as_bytes()));
|
||||
<span style="color:#66d9ef">let</span> _ <span style="color:#f92672">=</span> email_client.command(QuitCommand);</code></pre></div>
|
||||
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::*;
|
||||
|
||||
fn main() {
|
||||
let mut email_client: Client<NetworkStream> = Client::new();
|
||||
let _ = email_client.connect(&("localhost", SMTP_PORT), None);
|
||||
let _ = email_client.command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
|
||||
let _ = email_client.command(
|
||||
MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
|
||||
);
|
||||
let _ = email_client.command(
|
||||
RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
|
||||
);
|
||||
let _ = email_client.command(DataCommand);
|
||||
let _ = email_client.message(Box::new("Test email".as_bytes()));
|
||||
let _ = email_client.command(QuitCommand);
|
||||
}</code></pre></div>
|
||||
|
||||
<footer class=" footline" >
|
||||
|
||||
@@ -543,6 +582,22 @@ error handling:</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -669,20 +724,20 @@ error handling:</p>
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
<title>Stub transport :: Lettre site</title>
|
||||
|
||||
|
||||
<link href="/lettre/css/nucleus.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1516041983" rel="stylesheet">
|
||||
<link href="/lettre/css/nucleus.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/font-awesome.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hybrid.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/featherlight.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/perfect-scrollbar.min.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/auto-complete.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/theme.css?1517057321" rel="stylesheet">
|
||||
<link href="/lettre/css/hugo-theme.css?1517057321" rel="stylesheet">
|
||||
|
||||
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery-2.x.min.js?1517057321"></script>
|
||||
|
||||
<style type="text/css">
|
||||
:root #header + #content > #left > #rlblock_left{
|
||||
@@ -49,14 +49,14 @@
|
||||
<span data-search-clear=""><i class="fa fa-close"></i></span>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/lunr.min.js?1517057321"></script>
|
||||
<script type="text/javascript" src="/lettre/js/auto-complete.js?1517057321"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var baseurl = "https:\/\/lettre.github.io\/lettre";
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1516041983"></script>
|
||||
<script type="text/javascript" src="/lettre/js/search.js?1517057321"></script>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -133,6 +133,35 @@
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li data-nav-id="/lettre/creating-messages/email/" title="Email creation" class="dd-item ">
|
||||
<a href="/lettre/creating-messages/email/">
|
||||
Email creation
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -356,19 +385,23 @@
|
||||
|
||||
<p>The stub transport only logs message envelope and drops the content. It can be useful for
|
||||
testing purposes.</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">use</span> lettre::stub::StubEmailTransport;
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rust" data-lang="rust"><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">crate</span> lettre;
|
||||
|
||||
<span style="color:#66d9ef">use</span> lettre::stub::StubEmailTransport;
|
||||
<span style="color:#66d9ef">use</span> lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
|
||||
<span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> sender <span style="color:#f92672">=</span> StubEmailTransport::new_positive();
|
||||
<span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> sender.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
<span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">main</span>() {
|
||||
<span style="color:#66d9ef">let</span> email <span style="color:#f92672">=</span> SimpleSendableEmail::new(
|
||||
EmailAddress::new(<span style="color:#e6db74">"user@localhost"</span>.to_string()),
|
||||
vec<span style="color:#f92672">!</span>[EmailAddress::new(<span style="color:#e6db74">"root@localhost"</span>.to_string())],
|
||||
<span style="color:#e6db74">"message_id"</span>.to_string(),
|
||||
<span style="color:#e6db74">"Hello world"</span>.to_string(),
|
||||
);
|
||||
|
||||
<span style="color:#66d9ef">let</span> <span style="color:#66d9ef">mut</span> sender <span style="color:#f92672">=</span> StubEmailTransport::new_positive();
|
||||
<span style="color:#66d9ef">let</span> result <span style="color:#f92672">=</span> sender.send(<span style="color:#f92672">&</span>email);
|
||||
assert<span style="color:#f92672">!</span>(result.is_ok());
|
||||
}</code></pre></div>
|
||||
<p>Will log (when using a logger like <code>env_logger</code>):</p>
|
||||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost></code></pre></div>
|
||||
|
||||
@@ -449,6 +482,22 @@ assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -572,20 +621,20 @@ assert<span style="color:#f92672">!</span>(result.is_ok());</code></pre></div>
|
||||
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
||||
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
||||
</div>
|
||||
<script src="/lettre/js/clipboard.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1516041983"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1516041983"></script>
|
||||
<script src="/lettre/js/clipboard.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/perfect-scrollbar.jquery.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/jquery.sticky-kit.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/featherlight.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/html5shiv-printshiv.min.js?1517057321"></script>
|
||||
<script src="/lettre/js/highlight.pack.js?1517057321"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1516041983"></script>
|
||||
<script src="/lettre/js/learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1516041983"></script>
|
||||
<script src="/lettre/js/modernizr.custom.71422.js?1517057321"></script>
|
||||
<script src="/lettre/js/learn.js?1517057321"></script>
|
||||
<script src="/lettre/js/hugo-learn.js?1517057321"></script>
|
||||
|
||||
<link href="/lettre/mermaid/mermaid.css?1516041983" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1516041983"></script>
|
||||
<link href="/lettre/mermaid/mermaid.css?1517057321" type="text/css" rel="stylesheet" />
|
||||
<script src="/lettre/mermaid/mermaid.js?1517057321"></script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
<lastmod>2017-05-21T23:46:01+02:00</lastmod>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>https://lettre.github.io/lettre/creating-messages/email/</loc>
|
||||
<lastmod>2018-01-21T23:46:17+02:00</lastmod>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>https://lettre.github.io/lettre/sending-messages/file/</loc>
|
||||
<lastmod>2017-05-21T23:46:17+02:00</lastmod>
|
||||
|
||||
@@ -10,6 +10,7 @@ license = "MIT"
|
||||
authors = ["Alexis Mousset <contact@amousset.me>"]
|
||||
categories = ["email"]
|
||||
keywords = ["email", "smtp", "mailer"]
|
||||
build = "build.rs"
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "lettre/lettre" }
|
||||
@@ -29,6 +30,10 @@ serde_derive = { version = "^1.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "^0.5"
|
||||
skeptic = "^0.13"
|
||||
|
||||
[build-dependencies]
|
||||
skeptic = "^0.13"
|
||||
|
||||
[features]
|
||||
default = ["file-transport", "crammd5-auth", "smtp-transport", "sendmail-transport"]
|
||||
|
||||
8
lettre/build.rs
Normal file
8
lettre/build.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
extern crate skeptic;
|
||||
|
||||
use skeptic::*;
|
||||
|
||||
fn main() {
|
||||
let mdbook_files = markdown_files_of_directory("../website/content/sending-messages/");
|
||||
generate_doc_tests(&mdbook_files);
|
||||
}
|
||||
@@ -2,36 +2,6 @@
|
||||
//! `message_id.txt`.
|
||||
//! It can be useful for testing purposes, or if you want to keep track of sent messages.
|
||||
//!
|
||||
//! ```rust
|
||||
//! 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.txt`:
|
||||
//!
|
||||
//! ```text
|
||||
//! 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!
|
||||
//! ```
|
||||
|
||||
use EmailTransport;
|
||||
use SendableEmail;
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
//! The sendmail transport sends the email using the local sendmail command.
|
||||
//!
|
||||
//! ```rust
|
||||
//! 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());
|
||||
//! ```
|
||||
|
||||
use {EmailTransport, SendableEmail};
|
||||
use sendmail::error::SendmailResult;
|
||||
|
||||
@@ -12,20 +12,20 @@ use smtp::NUL;
|
||||
use smtp::error::Error;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
/// Accepted authentication mecanisms on an encrypted connection
|
||||
/// Accepted authentication mechanisms on an encrypted connection
|
||||
/// Trying LOGIN last as it is deprecated.
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
pub const DEFAULT_ENCRYPTED_MECHANISMS: &[Mechanism] =
|
||||
&[Mechanism::Plain, Mechanism::CramMd5, Mechanism::Login];
|
||||
/// Accepted authentication mecanisms on an encrypted connection
|
||||
/// Accepted authentication mechanisms on an encrypted connection
|
||||
/// Trying LOGIN last as it is deprecated.
|
||||
#[cfg(not(feature = "crammd5-auth"))]
|
||||
pub const DEFAULT_ENCRYPTED_MECHANISMS: &[Mechanism] = &[Mechanism::Plain, Mechanism::Login];
|
||||
|
||||
/// Accepted authentication mecanisms on an unencrypted connection
|
||||
/// Accepted authentication mechanisms on an unencrypted connection
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
pub const DEFAULT_UNENCRYPTED_MECHANISMS: &[Mechanism] = &[Mechanism::CramMd5];
|
||||
/// Accepted authentication mecanisms on an unencrypted connection
|
||||
/// Accepted authentication mechanisms on an unencrypted connection
|
||||
/// When CRAMMD5 support is not enabled, no mechanisms are allowed.
|
||||
#[cfg(not(feature = "crammd5-auth"))]
|
||||
pub const DEFAULT_UNENCRYPTED_MECHANISMS: &[Mechanism] = &[];
|
||||
@@ -110,14 +110,18 @@ impl Mechanism {
|
||||
challenge: Option<&str>)
|
||||
-> Result<String, Error> {
|
||||
match *self {
|
||||
Mechanism::Plain => match challenge {
|
||||
Some(_) => Err(Error::Client("This mechanism does not expect a challenge")),
|
||||
None => Ok(format!("{}{}{}{}",
|
||||
Mechanism::Plain => {
|
||||
match challenge {
|
||||
Some(_) => Err(Error::Client("This mechanism does not expect a challenge")),
|
||||
None => {
|
||||
Ok(format!("{}{}{}{}",
|
||||
NUL,
|
||||
credentials.username,
|
||||
NUL,
|
||||
credentials.password)),
|
||||
},
|
||||
credentials.password))
|
||||
}
|
||||
}
|
||||
}
|
||||
Mechanism::Login => {
|
||||
let decoded_challenge = match challenge {
|
||||
Some(challenge) => challenge,
|
||||
|
||||
@@ -44,11 +44,13 @@ impl NetworkStream {
|
||||
match *self {
|
||||
NetworkStream::Tcp(ref s) => s.peer_addr(),
|
||||
NetworkStream::Tls(ref s) => s.get_ref().peer_addr(),
|
||||
NetworkStream::Mock(_) => Ok(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127,
|
||||
0,
|
||||
0,
|
||||
1),
|
||||
80))),
|
||||
NetworkStream::Mock(_) => {
|
||||
Ok(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127,
|
||||
0,
|
||||
0,
|
||||
1),
|
||||
80)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +110,12 @@ impl Connector for NetworkStream {
|
||||
let tcp_stream = TcpStream::connect(addr)?;
|
||||
|
||||
match tls_parameters {
|
||||
Some(context) => context.connector
|
||||
.connect(context.domain.as_ref(), tcp_stream)
|
||||
.map(NetworkStream::Tls)
|
||||
.map_err(|e| io::Error::new(ErrorKind::Other, e)),
|
||||
Some(context) => {
|
||||
context.connector
|
||||
.connect(context.domain.as_ref(), tcp_stream)
|
||||
.map(NetworkStream::Tls)
|
||||
.map_err(|e| io::Error::new(ErrorKind::Other, e))
|
||||
}
|
||||
None => Ok(NetworkStream::Tcp(tcp_stream)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,10 +266,12 @@ impl AuthCommand {
|
||||
debug!("auth encoded challenge: {}", encoded_challenge);
|
||||
|
||||
let decoded_challenge = match base64::decode(&encoded_challenge) {
|
||||
Ok(challenge) => match String::from_utf8(challenge) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(Error::Utf8Parsing(error)),
|
||||
},
|
||||
Ok(challenge) => {
|
||||
match String::from_utf8(challenge) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(Error::Utf8Parsing(error)),
|
||||
}
|
||||
}
|
||||
Err(error) => return Err(Error::ChallengeParsing(error)),
|
||||
};
|
||||
|
||||
|
||||
@@ -52,14 +52,18 @@ impl StdError for Error {
|
||||
match *self {
|
||||
// Try to display the first line of the server's response that usually
|
||||
// contains a short humanly readable error message
|
||||
Transient(ref err) => match err.first_line() {
|
||||
Some(line) => line,
|
||||
None => "undetailed transient error during SMTP transaction",
|
||||
},
|
||||
Permanent(ref err) => match err.first_line() {
|
||||
Some(line) => line,
|
||||
None => "undetailed permanent error during SMTP transaction",
|
||||
},
|
||||
Transient(ref err) => {
|
||||
match err.first_line() {
|
||||
Some(line) => line,
|
||||
None => "undetailed transient error during SMTP transaction",
|
||||
}
|
||||
}
|
||||
Permanent(ref err) => {
|
||||
match err.first_line() {
|
||||
Some(line) => line,
|
||||
None => "undetailed permanent error during SMTP transaction",
|
||||
}
|
||||
}
|
||||
ResponseParsing(err) => err,
|
||||
ChallengeParsing(ref err) => err.description(),
|
||||
Utf8Parsing(ref err) => err.description(),
|
||||
|
||||
@@ -132,21 +132,23 @@ impl ServerInfo {
|
||||
"STARTTLS" => {
|
||||
features.insert(Extension::StartTls);
|
||||
}
|
||||
"AUTH" => for &mechanism in &splitted[1..] {
|
||||
match mechanism {
|
||||
"PLAIN" => {
|
||||
features.insert(Extension::Authentication(Mechanism::Plain));
|
||||
"AUTH" => {
|
||||
for &mechanism in &splitted[1..] {
|
||||
match mechanism {
|
||||
"PLAIN" => {
|
||||
features.insert(Extension::Authentication(Mechanism::Plain));
|
||||
}
|
||||
"LOGIN" => {
|
||||
features.insert(Extension::Authentication(Mechanism::Login));
|
||||
}
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
"CRAM-MD5" => {
|
||||
features.insert(Extension::Authentication(Mechanism::CramMd5));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
"LOGIN" => {
|
||||
features.insert(Extension::Authentication(Mechanism::Login));
|
||||
}
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
"CRAM-MD5" => {
|
||||
features.insert(Extension::Authentication(Mechanism::CramMd5));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,95 +13,6 @@
|
||||
//! * STARTTLS ([RFC 2487](http://tools.ietf.org/html/rfc2487))
|
||||
//! * SMTPUTF8 ([RFC 6531](http://tools.ietf.org/html/rfc6531))
|
||||
//!
|
||||
//! #### Simple example
|
||||
//!
|
||||
//! This is the most basic example of usage:
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
//!
|
||||
//! 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(),
|
||||
//! );
|
||||
//!
|
||||
//! // Open a local connection on port 25
|
||||
//! let mut mailer =
|
||||
//! SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
//! // Send the email
|
||||
//! let result = mailer.send(&email);
|
||||
//!
|
||||
//! assert!(result.is_ok());
|
||||
//! ```
|
||||
//!
|
||||
//! #### Complete example
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
//! use lettre::smtp::extension::ClientId;
|
||||
//! use lettre::smtp::ConnectionReuseParameters;
|
||||
//!
|
||||
//!
|
||||
//! 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(),
|
||||
//! );
|
||||
//!
|
||||
//! // Connect to a remote server on a custom port
|
||||
//! let mut mailer = SmtpTransport::simple_builder("server.tld").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();
|
||||
//!
|
||||
//! let result_1 = mailer.send(&email);
|
||||
//! assert!(result_1.is_ok());
|
||||
//!
|
||||
//! // 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();
|
||||
//! ```
|
||||
//!
|
||||
//! #### Lower level
|
||||
//!
|
||||
//! You can also send commands, here is a simple email transaction without
|
||||
//! error handling:
|
||||
//!
|
||||
//! ```rust
|
||||
//! 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::*;
|
||||
//!
|
||||
//! let mut email_client: Client<NetworkStream> = Client::new();
|
||||
//! let _ = email_client.connect(&("localhost", SMTP_PORT), None);
|
||||
//! let _ = email_client.command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
|
||||
//! let _ = email_client.command(
|
||||
//! MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
|
||||
//! );
|
||||
//! let _ = email_client.command(
|
||||
//! RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
|
||||
//! );
|
||||
//! let _ = email_client.command(DataCommand);
|
||||
//! let _ = email_client.message(Box::new("Test email".as_bytes()));
|
||||
//! let _ = email_client.command(QuitCommand);
|
||||
//! ```
|
||||
|
||||
use EmailTransport;
|
||||
use SendableEmail;
|
||||
@@ -215,14 +126,16 @@ impl SmtpTransportBuilder {
|
||||
let mut addresses = addr.to_socket_addrs()?;
|
||||
|
||||
match addresses.next() {
|
||||
Some(addr) => Ok(SmtpTransportBuilder { server_addr: addr,
|
||||
security: security,
|
||||
smtp_utf8: false,
|
||||
credentials: None,
|
||||
connection_reuse: ConnectionReuseParameters::NoReuse,
|
||||
hello_name: ClientId::hostname(),
|
||||
authentication_mechanism: None,
|
||||
timeout: Some(Duration::new(60, 0)), }),
|
||||
Some(addr) => {
|
||||
Ok(SmtpTransportBuilder { server_addr: addr,
|
||||
security: security,
|
||||
smtp_utf8: false,
|
||||
credentials: None,
|
||||
connection_reuse: ConnectionReuseParameters::NoReuse,
|
||||
hello_name: ClientId::hostname(),
|
||||
authentication_mechanism: None,
|
||||
timeout: Some(Duration::new(60, 0)), })
|
||||
}
|
||||
None => Err(Error::Resolution),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,6 @@
|
||||
//! The stub transport only logs message envelope and drops the content. It can be useful for
|
||||
//! testing purposes.
|
||||
//!
|
||||
//! ```rust
|
||||
//! 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`):
|
||||
//!
|
||||
//! ```text
|
||||
//! b7c211bc-9811-45ce-8cd9-68eab575d695: from=<user@localhost> to=<root@localhost>
|
||||
//! ```
|
||||
|
||||
use EmailTransport;
|
||||
use SendableEmail;
|
||||
|
||||
1
lettre/tests/skeptic.rs
Normal file
1
lettre/tests/skeptic.rs
Normal file
@@ -0,0 +1 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));
|
||||
@@ -10,12 +10,17 @@ license = "MIT"
|
||||
authors = ["Alexis Mousset <contact@amousset.me>"]
|
||||
categories = ["email"]
|
||||
keywords = ["email", "mailer"]
|
||||
build = "build.rs"
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "lettre/lettre_email" }
|
||||
|
||||
[dev-dependencies]
|
||||
lettre = { version = "^0.8", path = "../lettre", features = ["smtp-transport"] }
|
||||
skeptic = "^0.13"
|
||||
|
||||
[build-dependencies]
|
||||
skeptic = "^0.13"
|
||||
|
||||
[dependencies]
|
||||
email = "^0.0"
|
||||
|
||||
11
lettre_email/build.rs
Normal file
11
lettre_email/build.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
extern crate skeptic;
|
||||
|
||||
use skeptic::*;
|
||||
|
||||
fn main() {
|
||||
let mut mdbook_files = markdown_files_of_directory("../website/content/creating-messages/");
|
||||
// Also add "README.md" to the list of files.
|
||||
mdbook_files.push("README.md".into());
|
||||
|
||||
generate_doc_tests(&mdbook_files);
|
||||
}
|
||||
@@ -1,55 +1,4 @@
|
||||
//! Lettre is a mailer written in Rust. It provides a simple email builder and several transports.
|
||||
//!
|
||||
//! ## Overview
|
||||
//!
|
||||
//! The `email` part builds email messages. For now, it does not support attachments.
|
||||
//! An email is built using an `EmailBuilder`. The simplest email could be:
|
||||
//!
|
||||
//! ```rust
|
||||
//! use lettre_email::EmailBuilder;
|
||||
//!
|
||||
//! // Create an email
|
||||
//! let email = EmailBuilder::new()
|
||||
//! // Addresses can be specified by the tuple (email, alias)
|
||||
//! .to(("user@example.org", "Firstname Lastname"))
|
||||
//! // ... or by an address only
|
||||
//! .from("user@example.com")
|
||||
//! .subject("Hi, Hello world")
|
||||
//! .text("Hello world.")
|
||||
//! .build();
|
||||
//!
|
||||
//! assert!(email.is_ok());
|
||||
//! ```
|
||||
//!
|
||||
//! When the `build` method is called, the `EmailBuilder` will add the missing headers (like
|
||||
//! `Message-ID` or `Date`) and check for missing necessary ones (like `From` or `To`). It will
|
||||
//! then generate an `Email` that can be sent.
|
||||
//!
|
||||
//! The `text()` method will create a plain text email, while the `html()` method will create an
|
||||
//! HTML email. You can use the `alternative()` method to provide both versions, using plain text
|
||||
//! as fallback for the HTML version.
|
||||
//!
|
||||
//! Below is a more complete example, not using method chaining:
|
||||
//!
|
||||
//! ```rust
|
||||
//! use lettre_email::EmailBuilder;
|
||||
//!
|
||||
//! let mut builder = EmailBuilder::new();
|
||||
//! builder.add_to(("user@example.org", "Alias name"));
|
||||
//! builder.add_cc(("user@example.net", "Alias name"));
|
||||
//! builder.add_from("no-reply@example.com");
|
||||
//! builder.add_from("no-reply@example.eu");
|
||||
//! builder.set_sender("no-reply@example.com");
|
||||
//! builder.set_subject("Hello world");
|
||||
//! builder.set_alternative("<h2>Hi, Hello world.</h2>", "Hi, Hello world.");
|
||||
//! builder.add_reply_to("contact@example.com");
|
||||
//! builder.add_header(("X-Custom-Header", "my header"));
|
||||
//!
|
||||
//! let email = builder.build();
|
||||
//! assert!(email.is_ok());
|
||||
//! ```
|
||||
//!
|
||||
//! See the `EmailBuilder` documentation for a complete list of methods.
|
||||
//! Lettre is a mailer written in Rust. lettre_email provides a simple email builder.
|
||||
//!
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/lettre_email/0.8.0")]
|
||||
@@ -626,13 +575,17 @@ impl EmailBuilder {
|
||||
|
||||
let actual_filename = match filename {
|
||||
Some(name) => name,
|
||||
None => match path.file_name() {
|
||||
Some(name) => match name.to_str() {
|
||||
Some(name) => name,
|
||||
None => {
|
||||
match path.file_name() {
|
||||
Some(name) => {
|
||||
match name.to_str() {
|
||||
Some(name) => name,
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
}
|
||||
}
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
},
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let content = PartBuilder::new().body(body)
|
||||
@@ -776,9 +729,11 @@ impl EmailBuilder {
|
||||
{
|
||||
match *receiver {
|
||||
Address::Mailbox(ref m) => e.add_to(m.address.clone()),
|
||||
Address::Group(_, ref ms) => for m in ms.iter() {
|
||||
e.add_to(m.address.clone());
|
||||
},
|
||||
Address::Group(_, ref ms) => {
|
||||
for m in ms.iter() {
|
||||
e.add_to(m.address.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.to.is_empty() {
|
||||
|
||||
1
lettre_email/tests/skeptic.rs
Normal file
1
lettre_email/tests/skeptic.rs
Normal file
@@ -0,0 +1 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));
|
||||
@@ -8,5 +8,4 @@ weight = 2
|
||||
|
||||
### Creating messages
|
||||
|
||||
The documentation for the `lettre_email` is available on https://docs.rs/lettre_email/0.7.0/lettre_email/ for now.
|
||||
|
||||
This section explains how to create emails.
|
||||
69
website/content/creating-messages/email.md
Normal file
69
website/content/creating-messages/email.md
Normal file
@@ -0,0 +1,69 @@
|
||||
+++
|
||||
date = "2018-01-21T23:46:17+02:00"
|
||||
title = "Email creation"
|
||||
toc = true
|
||||
weight = 4
|
||||
|
||||
+++
|
||||
|
||||
#### Simple example
|
||||
|
||||
The `email` part builds email messages. For now, it does not support attachments.
|
||||
An email is built using an `EmailBuilder`. The simplest email could be:
|
||||
|
||||
```rust
|
||||
extern crate lettre_email;
|
||||
|
||||
use lettre_email::EmailBuilder;
|
||||
|
||||
fn main() {
|
||||
// Create an email
|
||||
let email = EmailBuilder::new()
|
||||
// Addresses can be specified by the tuple (email, alias)
|
||||
.to(("user@example.org", "Firstname Lastname"))
|
||||
// ... or by an address only
|
||||
.from("user@example.com")
|
||||
.subject("Hi, Hello world")
|
||||
.text("Hello world.")
|
||||
.build();
|
||||
|
||||
assert!(email.is_ok());
|
||||
}
|
||||
```
|
||||
|
||||
When the `build` method is called, the `EmailBuilder` will add the missing headers (like
|
||||
`Message-ID` or `Date`) and check for missing necessary ones (like `From` or `To`). It will
|
||||
then generate an `Email` that can be sent.
|
||||
|
||||
The `text()` method will create a plain text email, while the `html()` method will create an
|
||||
HTML email. You can use the `alternative()` method to provide both versions, using plain text
|
||||
as fallback for the HTML version.
|
||||
|
||||
#### Complete example
|
||||
|
||||
Below is a more complete example, not using method chaining:
|
||||
|
||||
```rust
|
||||
extern crate lettre_email;
|
||||
|
||||
use lettre_email::EmailBuilder;
|
||||
|
||||
fn main() {
|
||||
let mut builder = EmailBuilder::new();
|
||||
builder.add_to(("user@example.org", "Alias name"));
|
||||
builder.add_cc(("user@example.net", "Alias name"));
|
||||
builder.add_from("no-reply@example.com");
|
||||
builder.add_from("no-reply@example.eu");
|
||||
builder.set_sender("no-reply@example.com");
|
||||
builder.set_subject("Hello world");
|
||||
builder.set_alternative("<h2>Hi, Hello world.</h2>", "Hi, Hello world.");
|
||||
builder.add_reply_to("contact@example.com");
|
||||
builder.add_header(("X-Custom-Header", "my header"));
|
||||
|
||||
let email = builder.build();
|
||||
assert!(email.is_ok());
|
||||
}
|
||||
```
|
||||
|
||||
See the `EmailBuilder` documentation for a complete list of methods.
|
||||
|
||||
@@ -11,22 +11,26 @@ The file transport writes the emails to the given directory. The name of the fil
|
||||
It can be useful for testing purposes, or if you want to keep track of sent messages.
|
||||
|
||||
```rust
|
||||
extern crate lettre;
|
||||
|
||||
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());
|
||||
fn main() {
|
||||
// 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.txt`:
|
||||
|
||||
@@ -12,7 +12,7 @@ emails have to implement `SendableEmail`, which is the case for emails created w
|
||||
The following transports are available:
|
||||
|
||||
* The `SmtpTransport` uses the SMTP protocol to send the message over the network. It is
|
||||
the prefered way of sending emails.
|
||||
the preferred way of sending emails.
|
||||
* The `SendmailTransport` uses the sendmail command to send messages. It is an alternative to
|
||||
the SMTP transport.
|
||||
* The `FileTransport` creates a file containing the email content to be sent. It can be used
|
||||
|
||||
@@ -8,18 +8,22 @@ weight = 3
|
||||
|
||||
The sendmail transport sends the email using the local sendmail command.
|
||||
|
||||
``` rust
|
||||
```rust,no_run
|
||||
extern crate lettre;
|
||||
|
||||
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());
|
||||
fn main() {
|
||||
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());
|
||||
}
|
||||
```
|
||||
|
||||
@@ -8,10 +8,10 @@ weight = 2
|
||||
|
||||
This transport uses the SMTP protocol to send emails over the network (locally or remotely).
|
||||
|
||||
It is desinged to be:
|
||||
It is designed to be:
|
||||
|
||||
* Secured: email are encrypted by default
|
||||
* Modern: Unicode support for email content and sender/recipient adresses when compatible
|
||||
* Modern: Unicode support for email content and sender/recipient addresses when compatible
|
||||
* Fast: supports tcp connection reuse
|
||||
|
||||
This client is designed to send emails to a relay server, and should *not* be used to send
|
||||
@@ -23,64 +23,70 @@ The relay server can be the local email server, a specific host or a third-party
|
||||
|
||||
This is the most basic example of usage:
|
||||
|
||||
``` rust
|
||||
```rust,no_run
|
||||
extern crate lettre;
|
||||
|
||||
use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
|
||||
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(),
|
||||
);
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer =
|
||||
SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
// Send the email
|
||||
let result = mailer.send(&email);
|
||||
|
||||
assert!(result.is_ok());
|
||||
fn main() {
|
||||
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(),
|
||||
);
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer =
|
||||
SmtpTransport::builder_unencrypted_localhost().unwrap().build();
|
||||
// Send the email
|
||||
let result = mailer.send(&email);
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
```
|
||||
|
||||
#### Complete example
|
||||
|
||||
``` rust
|
||||
```rust,no_run
|
||||
extern crate lettre;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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(),
|
||||
);
|
||||
|
||||
// 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();
|
||||
|
||||
let result_1 = mailer.send(&email);
|
||||
assert!(result_1.is_ok());
|
||||
|
||||
// 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();
|
||||
fn main() {
|
||||
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(),
|
||||
);
|
||||
|
||||
// Connect to a remote server on a custom port
|
||||
let mut mailer = SmtpTransport::simple_builder("server.tld").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();
|
||||
|
||||
let result_1 = mailer.send(&email);
|
||||
assert!(result_1.is_ok());
|
||||
|
||||
// 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();
|
||||
}
|
||||
```
|
||||
|
||||
#### Lower level
|
||||
@@ -88,7 +94,9 @@ mailer.close();
|
||||
You can also send commands, here is a simple email transaction without
|
||||
error handling:
|
||||
|
||||
``` rust
|
||||
```rust,no_run
|
||||
extern crate lettre;
|
||||
|
||||
use lettre::EmailAddress;
|
||||
use lettre::smtp::SMTP_PORT;
|
||||
use lettre::smtp::client::Client;
|
||||
@@ -96,17 +104,19 @@ use lettre::smtp::client::net::NetworkStream;
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::commands::*;
|
||||
|
||||
let mut email_client: Client<NetworkStream> = Client::new();
|
||||
let _ = email_client.connect(&("localhost", SMTP_PORT), None);
|
||||
let _ = email_client.command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
|
||||
let _ = email_client.command(
|
||||
MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
|
||||
);
|
||||
let _ = email_client.command(
|
||||
RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
|
||||
);
|
||||
let _ = email_client.command(DataCommand);
|
||||
let _ = email_client.message(Box::new("Test email".as_bytes()));
|
||||
let _ = email_client.command(QuitCommand);
|
||||
fn main() {
|
||||
let mut email_client: Client<NetworkStream> = Client::new();
|
||||
let _ = email_client.connect(&("localhost", SMTP_PORT), None);
|
||||
let _ = email_client.command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
|
||||
let _ = email_client.command(
|
||||
MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
|
||||
);
|
||||
let _ = email_client.command(
|
||||
RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
|
||||
);
|
||||
let _ = email_client.command(DataCommand);
|
||||
let _ = email_client.message(Box::new("Test email".as_bytes()));
|
||||
let _ = email_client.command(QuitCommand);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -9,20 +9,24 @@ weight = 5
|
||||
The stub transport only logs message envelope and drops the content. It can be useful for
|
||||
testing purposes.
|
||||
|
||||
``` rust
|
||||
```rust
|
||||
extern crate lettre;
|
||||
|
||||
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());
|
||||
fn main() {
|
||||
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`):
|
||||
|
||||
Reference in New Issue
Block a user