Created
July 20, 2019 13:49
-
-
Save frankyxhl/cf0f731f5cabfdec1aeb56357eefc4f9 to your computer and use it in GitHub Desktop.
Rust send smtp email by Zoho code example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// === 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( | |
"[email protected]".to_string(), | |
"password".to_string(), | |
); | |
let mail = Email::builder() | |
.to("[email protected]") | |
.from("[email protected]") | |
.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