Repository: lettre/lettre (language: rust)

Issue:
Gmail example for 0.8
Please include this example, this maybe works:
I think this will stop working in 0.9, since the devs renamed everything.
I understand why everything was renamed, but boy did this take longer than necessary...

use lettre::{EmailTransport, SimpleSendableEmail,SmtpTransport    };
use lettre::smtp::authentication::Credentials;


fn send(){

    // generate all xmls for all domains.
    let report = String::from("Subject: the_subject\n\n the message goes here");

    let email = SimpleSendableEmail::new(
        "youremail@gmail.com".to_string(),
        &["destination@example.com".to_string()],
        "2018-05-01T00:00:01".to_string(),
        report,
    ).expect("Failed to build message");

    let c:Credentials = Credentials::new("youremail@gmail.com".to_string(),"yourpassword".to_string());    
    let mut transport:SmtpTransport = SmtpTransport::simple_builder("smtp.gmail.com")
        .expect("Failed to create transport")
        .credentials(c).build();

    println!("{:?}", transport.send(&email));

}

it may work, or not...



Discussion / hints:
Thank you for posting an example with gmail. I think this would be a fine example and would save time for many people using this crate.
no worries, you can copy and paste the code into the repo. I don't mind.

Fix patch:
diff --git a/lettre/Cargo.toml b/lettre/Cargo.toml
index c51a59ffa..cced3bafc 100644
--- a/lettre/Cargo.toml
+++ b/lettre/Cargo.toml
@@ -47,3 +47,7 @@ sendmail-transport = []
 [[example]]
 name = "smtp"
 required-features = ["smtp-transport"]
+
+[[example]]
+name = "smtp_gmail"
+required-features = ["smtp-transport"]
diff --git a/lettre/examples/smtp_gmail.rs b/lettre/examples/smtp_gmail.rs
new file mode 100644
index 000000000..3bc5ec353
--- /dev/null
+++ b/lettre/examples/smtp_gmail.rs
@@ -0,0 +1,38 @@
+extern crate lettre;
+
+use lettre::smtp::authentication::Credentials;
+use lettre::{EmailAddress, Envelope, SendableEmail, SmtpClient, Transport};
+
+fn main() {
+    let email = SendableEmail::new(
+        Envelope::new(
+            Some(EmailAddress::new("from@gmail.com".to_string()).unwrap()),
+            vec![EmailAddress::new("to@example.com".to_string()).unwrap()],
+        )
+        .unwrap(),
+        "id".to_string(),
+        "Hello example".to_string().into_bytes(),
+    );
+
+    let creds = Credentials::new(
+        "example_username".to_string(),
+        "example_password".to_string(),
+    );
+
+    // Open a remote connection to gmail
+    let mut mailer = SmtpClient::new_simple("smtp.gmail.com")
+        .unwrap()
+        .credentials(creds)
+        .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());
+}
diff --git a/lettre_email/examples/smtp_gmail.rs b/lettre_email/examples/smtp_gmail.rs
new file mode 100644
index 000000000..4852220ef
--- /dev/null
+++ b/lettre_email/examples/smtp_gmail.rs
@@ -0,0 +1,38 @@
+extern crate lettre;
+extern crate lettre_email;
+
+use lettre::smtp::authentication::Credentials;
+use lettre::{SmtpClient, Transport};
+use lettre_email::Email;
+
+fn main() {
+    let email = Email::builder()
+        .to("to@example.org")
+        .from("from@example.com")
+        .subject("subject")
+        .text("message")
+        .build()
+        .unwrap();
+
+    let creds = Credentials::new(
+        "example_username".to_string(),
+        "example_password".to_string(),
+    );
+
+    // Open connection to gmail
+    let mut mailer = SmtpClient::new_simple("smtp.gmail.com")
+        .unwrap()
+        .credentials(creds)
+        .transport();
+
+    // Send the email
+    let result = mailer.send(email.into());
+
+    if result.is_ok() {
+        println!("Email sent");
+    } else {
+        println!("Could not send email: {:?}", result);
+    }
+
+    assert!(result.is_ok());
+}


Test patch: