Skip to content

Instantly share code, notes, and snippets.

@frankyxhl

frankyxhl/main.rs

Created Jul 20, 2019
Embed
What would you like to do?
Rust send smtp email by Zoho code example
// === In Cargo.toml file======
// lettre = "0.9.2"
// lettre_email = "0.9.2"
// native-tls = "0.2.3"
// ============================
use lettre_email::Email;
use lettre::smtp::authentication::Credentials;
use lettre::{ClientSecurity, ClientTlsParameters, SmtpClient, Transport};
use native_tls::TlsConnector;
fn main() {
let creds = Credentials::new(
"login_account@example.com".to_string(),
"password".to_string(),
);
let mail = Email::builder()
.to("example@example.com")
.from("example@example.com")
.subject("Subject")
.body("Body Content")
.build();
let connector = TlsConnector::new().unwrap();
let tls_params = ClientTlsParameters::new("smtp.zoho.com".to_string(), connector);
let security = ClientSecurity::Wrapper(tls_params);
let mut mailer = SmtpClient::new("smtp.zoho.com:465", security)
.unwrap()
.credentials(creds).transport();
mailer.send(mail.unwrap().into()).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.