[−][src]Module new_tokio_smtp::send_mail
[feature: send-mail
] provides the send_mail functionality
Send mail is a thin abstractions around sending commands,
which combines the sending of the MAIL
, RCPT
, DATA
commands with knowledge about wether or not SMTPUTF8
needs to be used.
Example
use std::iter::once as one; use futures::stream::{self, Stream}; use futures::future::{self, lazy, Future}; use new_tokio_smtp::error::GeneralError; use new_tokio_smtp::{Connection, ConnectionConfig}; use new_tokio_smtp::send_mail::{ Mail, EncodingRequirement, MailAddress, MailEnvelop }; let config = mock_connection_config(); let raw_mail = concat!( "Date: Thu, 14 Jun 2018 11:22:18 +0000\r\n", "From: <no-reply@test.test>\r\n", "\r\n", "...\r\n" ); // this normally adapts to a higher level abstraction // of mail then this crate provides let mail_data = Mail::new(EncodingRequirement::None, raw_mail.to_owned()); // the from_unchecked normally can be used if we know the address is valid // a mail address parser will be added at some point in the future let sender = MailAddress::from_unchecked("test@sender.test"); let send_to = MailAddress::from_unchecked("test@receiver.test"); let mail = MailEnvelop::new(sender, vec1![ send_to ], mail_data); let mail2 = mail.clone(); let config2 = config.clone(); mock_run_with_tokio(lazy(move || { Connection::connect(config) .map_err(GeneralError::from) .and_then(|con| con.send_mail(mail).map_err(Into::into)) .and_then(|(con, mail_result)| { if let Err((idx, err)) = mail_result { println!("sending mail failed: {}", err) } con.quit().map_err(Into::into) }).then(|res|{ match res { Ok(_) => println!("done, and closed connection"), Err(err) => println!("problem with connection: {}", err) } Result::Ok::<(),()>(()) }) })); // This is only overhead as we skipped any (fallible) mail encoding step let mail2: Result<_, GeneralError> = Ok(mail2); //or simpler mock_run_with_tokio(lazy(move || { // it accepts a iterator over mails, Connection::connect_send_quit(config2, one(mail2)) //Stream::for_each is conceptually broken in futures v0.1 .then(|res| Ok(res)) .for_each(|result| { if let Err(err) = result { println!("sending mail failed: {}", err); } else { println!("successfully send mail") } Ok(()) }) }));
Structs
EnvelopData | POD representing the smtp envelops from,to's |
A simplified representation of a mail consisting of an | |
MailAddress | A simple |
MailEnvelop | represents a mail envelop consisting of |
OnCompletion | Stream adapt resolving one function/future after the stream completes |
SendAllMails | Adapter to send all mails from an iterable instance through a smtp connection. |
Enums
EncodingRequirement | Specifies if the mail requires SMTPUTF8 (or Mime8bit) |
Functions
send_mail | Sends a mail specified through |
Type Definitions
MailSendFuture | Future returned by |
MailSendResult | The result of sending a mail |