Repository: lettre/lettre (language: rust)

Issue:
Readme example out of date.
Readme examples are showing code that no longer builds.

```
error[E0433]: failed to resolve: could not find `builder` in `lettre`
 --> src/main.rs:3:44
  |
3 | use lettre::{SmtpClient, Transport, Email, builder::mime::TEXT_PLAIN};
  |                                            ^^^^^^^ could not find `builder` in `lettre`

error[E0432]: unresolved import `lettre::Email`
 --> src/main.rs:3:37
  |
3 | use lettre::{SmtpClient, Transport, Email, builder::mime::TEXT_PLAIN};
  |                                     ^^^^^ no `Email` in the root

error[E0425]: cannot find value `TEXT_PLAIN` in this scope
  --> src/main.rs:14:63
   |
14 |         .attachment_from_file(Path::new("Cargo.toml"), None, &TEXT_PLAIN)
   |                                                               ^^^^^^^^^^ not found in this scope

error: aborting due to 3 previous errors
```


Discussion / hints:
is there a link to anywhere that can show me how to get this up and running the example code?
It's probably because you are reading the README for the master branch. If you are working with lettre 0.9.x I'd suggest reading the readme from the [v0.9.2 tag](https://github.com/lettre/lettre/tree/v0.9.2/) or on [crates.io](https://crates.io/crates/lettre)
Indeed, the README on master should probably be compatible with latest stable release though. I'll fix this.
![image](https://user-images.githubusercontent.com/5077917/71925459-16a83d00-315f-11ea-8df5-71ba8aac0b67.png)

This is the result I'm getting from running the crates.io example on 0.9 and 0.9.2.
I am also getting the same errors as @chrisbeaver while trying out the example from the README on ` v0.9.2 tag `. I would appreciate any up-to-date examples to get this running. Thanks!
Agreed, there seems to be a bit of a mismatch. However, the examples from the [Lettre guide](https://lettre.at/sending-messages/smtp.html) seem to work for me.

That guide also shows how to create messages with the `lettre_email` crate. FYI, `SmtpClient`'s `send` function expects a `SendableEmail`, whereas `lettre_mail` creates an `Email`. After way too long I realized that `Email` implements `Into<SendableEmail>`...

Minimal working example below, if you're interested. I'm using this with Fastmail's SMTP server.

```rust
use lettre::smtp::authentication::{Credentials, Mechanism};
use lettre::{SmtpClient, Transport};
use lettre_email::Email;
use std::env;

pub fn send_mail() {
    // Get SMTP configuration from environment
    let host = env::var("SMTP_HOST").expect("SMTP_HOST must be set");
    let user = env::var("SMTP_USER").expect("SMTP_USER must be set");
    let password = env::var("SMTP_PASSWORD").expect("SMTP_PASSWORD must be set");

    // Create the message
    let email = Email::builder()
        .to(("to@example.com", "Your Name"))
        .from(("from@example.com", "My Name"))
        .subject("Hi, Hello world")
        .alternative("<h2>Hi, Hello world.</h2>", "Hi, Hello world.")
        .build()
        .unwrap();

    // Create the SMTP client
    let mut mailer = SmtpClient::new_simple(host.as_str())
        .unwrap()
        .credentials(Credentials::new(user, password))
        .smtp_utf8(true)
        .authentication_mechanism(Mechanism::Plain)
        .transport();

    // Send the mail
    let result = mailer.send(email.into());
    assert!(result.is_ok());
    mailer.close();
}
```

Fix patch:
diff --git a/README.md b/README.md
index 513756f25..5552a83d5 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
 
 [![Crate](https://img.shields.io/crates/v/lettre.svg)](https://crates.io/crates/lettre)
 [![Docs](https://docs.rs/lettre/badge.svg)](https://docs.rs/lettre/)
-[![Required Rust version](https://img.shields.io/badge/rustc-1.40-green.svg)]()
+[![Required Rust version](https://img.shields.io/badge/rustc-1.20-green.svg)]()
 [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
 
 [![Gitter](https://badges.gitter.im/lettre/lettre.svg)](https://gitter.im/lettre/lettre?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
@@ -38,46 +38,44 @@ Lettre does not provide (for now):
 
 ## Example
 
-This library requires Rust 1.40 or newer.
+This library requires Rust 1.20 or newer.
 To use this library, add the following to your `Cargo.toml`:
 
+
 ```toml
 [dependencies]
-lettre = "0.10"
+lettre = "0.9"
+lettre_email = "0.9"
 ```
 
 ```rust,no_run
-extern crate lettre;
-
-use lettre::{SmtpClient, Transport, Message};
-use std::convert::TryInto;
-
-fn main() {
-    let email = Message::builder()
-        // Addresses can be specified by the tuple (email, alias)
-        .to(("user@example.org", "Firstname Lastname").try_into().unwrap())
-        // ... or by an address only
-        .from("user@example.com".parse().unwrap())
-        .subject("Hi, Hello world")
-        .body("Hello world.")
-        //.attachment_from_file(Path::new("Cargo.toml"), None, &TEXT_PLAIN)
-        // FIXME add back attachment example
-        .build()
-        .unwrap();
-
-    // Open a local connection on port 25
-    let mut mailer = SmtpClient::new_unencrypted_localhost().unwrap().transport();
-    // 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());
+use lettre::{EmailTransport, SmtpTransport};
+use lettre_email::EmailBuilder;
+use std::path::Path;
+
+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()
+    .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());
 ```
 
 ## Testing


Test patch: