Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lettre"
# remember to update html_root_url and README.md (Cargo.toml example and deps.rs badge)
version = "0.10.2"
version = "0.11.0"
description = "Email client"
readme = "README.md"
homepage = "https://lettre.rs"
Expand Down Expand Up @@ -48,13 +48,16 @@ rustls-pemfile = { version = "1", optional = true }
webpki-roots = { version = "0.22", optional = true }
boring = { version = "2.0.0", optional = true }

# SASL auth
rsasl = { version = "2.0.0", default-features = false, features = ["std", "provider_base64"], optional = true }

# async
futures-io = { version = "0.3.7", optional = true }
futures-util = { version = "0.3.7", default-features = false, features = ["io"], optional = true }
async-trait = { version = "0.1", optional = true }

## async-std
async-std = { version = "1.8", optional = true }
async-std = { version = "1.8", optional = true, features = ["unstable"] }
#async-native-tls = { version = "0.3.3", optional = true }
futures-rustls = { version = "0.22", optional = true }

Expand Down Expand Up @@ -83,6 +86,7 @@ tokio1_crate = { package = "tokio", version = "1", features = ["macros", "rt-mul
async-std = { version = "1.8", features = ["attributes"] }
serde_json = "1"
maud = "0.24"
rsasl = { version = "2.0.0", default-features = false, features = ["std", "provider_base64", "config_builder", "plain", "login", "scram-sha-2", "xoauth2"] }

[[bench]]
harness = false
Expand All @@ -97,7 +101,7 @@ mime03 = ["mime"]
file-transport = ["uuid", "tokio1_crate?/fs", "tokio1_crate?/io-util"]
file-transport-envelope = ["serde", "serde_json", "file-transport"]
sendmail-transport = ["tokio1_crate?/process", "tokio1_crate?/io-util", "async-std?/unstable"]
smtp-transport = ["base64", "nom", "socket2", "once_cell", "tokio1_crate?/rt", "tokio1_crate?/time", "tokio1_crate?/net"]
smtp-transport = ["base64", "nom", "socket2", "once_cell", "tokio1_crate?/rt", "tokio1_crate?/time", "tokio1_crate?/net", "rsasl"]

pool = ["futures-util"]

Expand All @@ -106,10 +110,10 @@ rustls-tls = ["webpki-roots", "rustls", "rustls-pemfile"]
boring-tls = ["boring"]

# async
async-std1 = ["async-std", "async-trait", "futures-io", "futures-util"]
async-std1 = ["async-std", "async-trait", "futures-io", "futures-util", "rsasl"]
#async-std1-native-tls = ["async-std1", "native-tls", "async-native-tls"]
async-std1-rustls-tls = ["async-std1", "rustls-tls", "futures-rustls"]
tokio1 = ["tokio1_crate", "async-trait", "futures-io", "futures-util"]
tokio1 = ["tokio1_crate", "async-trait", "futures-io", "futures-util", "rsasl"]
tokio1-native-tls = ["tokio1", "native-tls", "tokio1_native_tls_crate"]
tokio1-rustls-tls = ["tokio1", "rustls-tls", "tokio1_rustls"]
tokio1-boring-tls = ["tokio1", "boring-tls", "tokio1_boring"]
Expand Down
15 changes: 9 additions & 6 deletions examples/asyncstd1_smtp_starttls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use lettre::{
transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncStd1Executor,
AsyncTransport, Message,
};
use lettre::{AsyncSmtpTransport, AsyncStd1Executor, AsyncTransport, Message};
use rsasl::prelude::SASLConfig;

#[async_std::main]
async fn main() {
Expand All @@ -15,13 +13,18 @@ async fn main() {
.body(String::from("Be happy with async!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail using STARTTLS
let mailer: AsyncSmtpTransport<AsyncStd1Executor> =
AsyncSmtpTransport::<AsyncStd1Executor>::starttls_relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
15 changes: 9 additions & 6 deletions examples/asyncstd1_smtp_tls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use lettre::{
transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncStd1Executor,
AsyncTransport, Message,
};
use lettre::{AsyncSmtpTransport, AsyncStd1Executor, AsyncTransport, Message};
use rsasl::prelude::SASLConfig;

#[async_std::main]
async fn main() {
Expand All @@ -15,13 +13,18 @@ async fn main() {
.body(String::from("Be happy with async!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail
let mailer: AsyncSmtpTransport<AsyncStd1Executor> =
AsyncSmtpTransport::<AsyncStd1Executor>::relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
15 changes: 9 additions & 6 deletions examples/smtp_selfsigned.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::fs;

use lettre::{
transport::smtp::{
authentication::Credentials,
client::{Certificate, Tls, TlsParameters},
},
transport::smtp::client::{Certificate, Tls, TlsParameters},
Message, SmtpTransport, Transport,
};
use rsasl::prelude::SASLConfig;

fn main() {
tracing_subscriber::fmt::init();
Expand All @@ -27,13 +25,18 @@ fn main() {
.build()
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to the smtp server
let mailer = SmtpTransport::builder_dangerous("smtp.server.com")
.port(465)
.tls(Tls::Wrapper(tls))
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
12 changes: 9 additions & 3 deletions examples/smtp_starttls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
use lettre::{Message, SmtpTransport, Transport};
use rsasl::config::SASLConfig;

fn main() {
tracing_subscriber::fmt::init();
Expand All @@ -11,12 +12,17 @@ fn main() {
.body(String::from("Be happy!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail using STARTTLS
let mailer = SmtpTransport::starttls_relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
12 changes: 9 additions & 3 deletions examples/smtp_tls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
use lettre::{Message, SmtpTransport, Transport};
use rsasl::prelude::SASLConfig;

fn main() {
tracing_subscriber::fmt::init();
Expand All @@ -11,12 +12,17 @@ fn main() {
.body(String::from("Be happy!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail
let mailer = SmtpTransport::relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
15 changes: 9 additions & 6 deletions examples/tokio1_smtp_starttls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This line is only to make it compile from lettre's examples folder,
// since it uses Rust 2018 crate renaming to import tokio.
// Won't be needed in user's code.
use lettre::{
transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncTransport, Message,
Tokio1Executor,
};
use lettre::{AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor};
use rsasl::prelude::SASLConfig;
use tokio1_crate as tokio;

#[tokio::main]
Expand All @@ -19,13 +17,18 @@ async fn main() {
.body(String::from("Be happy with async!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail using STARTTLS
let mailer: AsyncSmtpTransport<Tokio1Executor> =
AsyncSmtpTransport::<Tokio1Executor>::starttls_relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
15 changes: 9 additions & 6 deletions examples/tokio1_smtp_tls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This line is only to make it compile from lettre's examples folder,
// since it uses Rust 2018 crate renaming to import tokio.
// Won't be needed in user's code.
use lettre::{
transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncTransport, Message,
Tokio1Executor,
};
use lettre::{AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor};
use rsasl::prelude::SASLConfig;
use tokio1_crate as tokio;

#[tokio::main]
Expand All @@ -19,13 +17,18 @@ async fn main() {
.body(String::from("Be happy with async!"))
.unwrap();

let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
let config = SASLConfig::with_credentials(
None,
"smtp_username".to_string(),
"smtp_password".to_string(),
)
.unwrap();

// Open a remote connection to gmail
let mailer: AsyncSmtpTransport<Tokio1Executor> =
AsyncSmtpTransport::<Tokio1Executor>::relay("smtp.gmail.com")
.unwrap()
.credentials(creds)
.sasl_config(config)
.build();

// Send the email
Expand Down
9 changes: 6 additions & 3 deletions src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
//! #
//! # #[cfg(all(feature = "builder", feature = "smtp-transport"))]
//! # fn main() -> Result<(), Box<dyn Error>> {
//! use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
//! # use std::sync::Arc;
//! use lettre::{Message, SmtpTransport, Transport};
//! use rsasl::prelude::SASLConfig;
//!
//! let email = Message::builder()
//! .from("NoBody <[email protected]>".parse()?)
Expand All @@ -65,11 +67,12 @@
//! .subject("Happy new year")
//! .body(String::from("Be happy!"))?;
//!
//! let creds = Credentials::new("smtp_username".to_string(), "smtp_password".to_string());
//! let config =
//! SASLConfig::with_credentials(None, "username".to_string(), "password".to_string()).unwrap();
//!
//! // Open a remote connection to the SMTP relay server
//! let mailer = SmtpTransport::relay("smtp.gmail.com")?
//! .credentials(creds)
//! .sasl_config(config)
//! .build();
//!
//! // Send the email
Expand Down
24 changes: 8 additions & 16 deletions src/transport/smtp/async_transport.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#[cfg(feature = "pool")]
use std::sync::Arc;
use std::{
fmt::{self, Debug},
marker::PhantomData,
sync::Arc,
time::Duration,
};

use async_trait::async_trait;
use rsasl::prelude::SASLConfig;

#[cfg(feature = "pool")]
use super::pool::async_impl::Pool;
#[cfg(feature = "pool")]
use super::PoolConfig;
use super::{
client::AsyncSmtpConnection, ClientId, Credentials, Error, Mechanism, Response, SmtpInfo,
};
use super::{client::AsyncSmtpConnection, ClientId, Error, Response, SmtpInfo};
#[cfg(feature = "async-std1")]
use crate::AsyncStd1Executor;
#[cfg(any(feature = "tokio1", feature = "async-std1"))]
Expand Down Expand Up @@ -225,15 +223,9 @@ impl AsyncSmtpTransportBuilder {
self
}

/// Set the authentication mechanism to use
pub fn credentials(mut self, credentials: Credentials) -> Self {
self.info.credentials = Some(credentials);
self
}

/// Set the authentication mechanism to use
pub fn authentication(mut self, mechanisms: Vec<Mechanism>) -> Self {
self.info.authentication = mechanisms;
/// Set the SASL configuration, which contains credentials and available mechanisms.
pub fn sasl_config(mut self, config: Arc<SASLConfig>) -> Self {
self.info.sasl = Some(config);
self
}

Expand Down Expand Up @@ -319,8 +311,8 @@ where
)
.await?;

if let Some(credentials) = &self.info.credentials {
conn.auth(&self.info.authentication, credentials).await?;
if let Some(config) = &self.info.sasl {
conn.auth(Arc::clone(config)).await?;
}
Ok(conn)
}
Expand Down
Loading