January 2019
Intermediate to advanced
520 pages
14h 32m
English
We use a separate thread that receives SendableEmail values and send them using the SMTP protocol. The following code creates an instance of SmtpClient and uses the credentials method to set the credentials for a connection:
fn spawn_sender() -> Sender<SendableEmail> { let (tx, rx) = channel(); let smtp = SmtpClient::new("localhost:2525", ClientSecurity::None) .expect("can't start smtp client"); let credentials = ("admin@example.com", "password").into_credentials(); let client = smtp.credentials(credentials); thread::spawn(move || { let mut mailer = SmtpTransport::new(client); for email in rx.iter() { let result = mailer.send(email); if let Err(err) = result { println!("Can't send mail: {}", err); } } mailer.close(); ...Read now
Unlock full access