Skip to content

Instantly share code, notes, and snippets.

@frankyxhl
Created July 20, 2019 13:49
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save frankyxhl/cf0f731f5cabfdec1aeb56357eefc4f9 to your computer and use it in GitHub Desktop.
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