From f10e4e81d0e267fbdccfea3f495c0afc065aec4c Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sat, 27 Jan 2018 13:46:13 +0100 Subject: [PATCH] feat(all): Move doc to website and test it --- .gitignore | 4 +- .travis.yml | 7 +- README.md | 37 + docs/404.html | 16 +- docs/creating-messages/email/index.html | 693 +++++++++++++++++++ docs/creating-messages/index.html | 103 ++- docs/creating-messages/index.xml | 10 + docs/getting-started/index.html | 93 ++- docs/getting-started/intro/index.html | 93 ++- docs/index.json | 18 +- docs/index.xml | 22 +- docs/json/search.json | 56 ++ docs/sending-messages/file/index.html | 121 +++- docs/sending-messages/index.html | 95 ++- docs/sending-messages/index.xml | 12 +- docs/sending-messages/intro/index.html | 95 ++- docs/sending-messages/sendmail/index.html | 119 +++- docs/sending-messages/smtp/index.html | 239 ++++--- docs/sending-messages/stub/index.html | 119 +++- docs/sitemap.xml | 5 + lettre/Cargo.toml | 5 + lettre/build.rs | 8 + lettre/src/file/mod.rs | 30 - lettre/src/sendmail/mod.rs | 15 - lettre/src/smtp/authentication.rs | 22 +- lettre/src/smtp/client/net.rs | 22 +- lettre/src/smtp/commands.rs | 10 +- lettre/src/smtp/error.rs | 20 +- lettre/src/smtp/extension.rs | 28 +- lettre/src/smtp/mod.rs | 107 +-- lettre/src/stub/mod.rs | 21 - lettre/tests/skeptic.rs | 1 + lettre_email/Cargo.toml | 5 + lettre_email/build.rs | 11 + lettre_email/src/lib.rs | 77 +-- lettre_email/tests/skeptic.rs | 1 + website/content/creating-messages/_index.md | 3 +- website/content/creating-messages/email.md | 69 ++ website/content/sending-messages/file.md | 26 +- website/content/sending-messages/intro.md | 2 +- website/content/sending-messages/sendmail.md | 26 +- website/content/sending-messages/smtp.md | 134 ++-- website/content/sending-messages/stub.md | 26 +- 43 files changed, 1903 insertions(+), 723 deletions(-) create mode 100644 docs/creating-messages/email/index.html create mode 100644 docs/json/search.json create mode 100644 lettre/build.rs create mode 100644 lettre/tests/skeptic.rs create mode 100644 lettre_email/build.rs create mode 100644 lettre_email/tests/skeptic.rs create mode 100644 website/content/creating-messages/email.md diff --git a/.gitignore b/.gitignore index e556b04..dd5cfaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .vscode/ -.project +.project/ +.idea/ +lettre.iml target/ /Cargo.lock diff --git a/.travis.yml b/.travis.yml index 794c405..02f559c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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=" diff --git a/README.md b/README.md index 590fb95..47b2131 100644 --- a/README.md +++ b/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: diff --git a/docs/404.html b/docs/404.html index cb082c5..5bb0623 100644 --- a/docs/404.html +++ b/docs/404.html @@ -9,14 +9,14 @@ 404 Page not found - - - - - - - - + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ + +
+
+ + + +
+ +

Email creation

+ + + + + + + +

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(("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:

+
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.

+ + +
+ +
+ + + +
+
+ + + +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + diff --git a/docs/creating-messages/index.html b/docs/creating-messages/index.html index 7b72101..47e5bdb 100644 --- a/docs/creating-messages/index.html +++ b/docs/creating-messages/index.html @@ -12,17 +12,17 @@ Creating messages :: Lettre site - - - - - - - - + + + + + + + + - +