-
-
Save ixna/0358982d12b8e6a0622edf842786d1a5 to your computer and use it in GitHub Desktop.
Rust send smtp email by Zoho code example
This file contains 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( | |
"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