soph_mail/support/
mail.rs1use crate::{config, config::Mailer, support::transports, Mail, MailResult};
2use soph_config::support::config;
3
4impl Mail {
5 pub fn new() -> MailResult<Self> {
6 let config = config().parse::<config::Mail>()?;
7
8 let transport = match config.mailer {
9 Mailer::Smtp => transports::smtp::new(&config)?,
10 Mailer::Stub => transports::stub::new(&config)?,
11 };
12
13 Ok(Self { transport, config })
14 }
15
16 pub fn mailer(&self) -> Mailer {
17 self.config.mailer.to_owned()
18 }
19}
20
21impl std::ops::Deref for Mail {
22 type Target = Box<dyn crate::traits::TransportTrait>;
23
24 fn deref(&self) -> &Self::Target {
25 &self.transport
26 }
27}