pub struct Email { /* private fields */ }Available on crate feature
email only.Expand description
A high-level email interface for sending emails.
This struct wraps a Transport implementation and provides
convenient methods for sending single or multiple email messages.
§Examples
use cot::common_types::Email;
use cot::email::EmailMessage;
use cot::email::transport::console::Console;
let email = cot::email::Email::new(Console::new());
let message = EmailMessage::builder()
.from(Email::try_from("no-reply@example.com").unwrap())
.to(vec![Email::try_from("user@example.com").unwrap()])
.subject("Greetings")
.body("Hello from cot!")
.build()?;
email.send(message).await?;Implementations§
Source§impl Email
impl Email
Sourcepub fn new(transport: impl Transport) -> Self
pub fn new(transport: impl Transport) -> Self
Create a new email sender using the given transport implementation.
§Examples
use cot::email::transport::console::Console;
use cot::email::{Email, EmailMessage};
let email = Email::new(Console::new());Sourcepub async fn send(&self, message: EmailMessage) -> EmailResult<()>
pub async fn send(&self, message: EmailMessage) -> EmailResult<()>
Send a single EmailMessage
§Errors
Returns an EmailError::Transport error if sending the email fails.
§Examples
use cot::common_types::Email;
use cot::email::EmailMessage;
use cot::email::transport::console::Console;
let email = cot::email::Email::new(Console::new());
let message = EmailMessage::builder()
.from(Email::try_from("no-reply@example.com").unwrap())
.to(vec![Email::try_from("user@example.com").unwrap()])
.subject("Greetings")
.body("Hello from cot!")
.build()?;
email.send(message).await?;Sourcepub async fn send_multiple(&self, messages: &[EmailMessage]) -> EmailResult<()>
pub async fn send_multiple(&self, messages: &[EmailMessage]) -> EmailResult<()>
Send multiple emails in sequence.
§Errors
Returns an EmailError::Transport if sending any of the emails fails.
§Examples
use cot::common_types::Email;
use cot::email::EmailMessage;
use cot::email::transport::console::Console;
let email = cot::email::Email::new(Console::new());
let message1 = EmailMessage::builder()
.from(Email::try_from("no-reply@email.com").unwrap())
.to(vec![Email::try_from("user1@example.com").unwrap()])
.subject("Hello User 1")
.body("This is the first email.")
.build()?;
let message2 = EmailMessage::builder()
.from(Email::try_from("no-reply@email.com").unwrap())
.to(vec![Email::try_from("user2@example.com").unwrap()])
.subject("Hello User 2")
.body("This is the second email.")
.build()?;
email.send_multiple(&[message1, message2]).await?;Sourcepub fn from_config(config: &EmailConfig) -> EmailResult<Self>
pub fn from_config(config: &EmailConfig) -> EmailResult<Self>
Construct an Email from the provided EmailConfig.
§Errors
Returns an EmailError::Transport error if creating the transport
backend fails from the config.
§Examples
use cot::config::{EmailConfig, EmailTransportConfig, EmailTransportTypeConfig};
use cot::email::Email;
use cot::email::transport::console::Console;
let config = EmailConfig {
transport: EmailTransportConfig::builder()
.transport_type(EmailTransportTypeConfig::Console)
.build(),
..Default::default()
};
let email = Email::from_config(&config);Trait Implementations§
Source§impl FromRequestHead for Email
impl FromRequestHead for Email
Source§async fn from_request_head(head: &RequestHead) -> Result<Self>
async fn from_request_head(head: &RequestHead) -> Result<Self>
Extracts data from the request head. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for Email
impl !UnwindSafe for Email
impl Freeze for Email
impl Send for Email
impl Sync for Email
impl Unpin for Email
impl UnsafeUnpin for Email
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
Available on crate feature
db only.Converts the type to the field type.