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