Skip to content

Commit

Permalink
Merge pull request #407 from amousset/readme-0-9
Browse files Browse the repository at this point in the history
fix(doc): README should be compatible with latest stabel release
  • Loading branch information
amousset committed Apr 19, 2020
2 parents 8f31fb9 + 7d29d77 commit de277a2
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de277a2

Please sign in to comment.