use async_trait::async_trait;
use crate::email::PreparedEmail;
use crate::error::MailError;
use crate::mailer::{DeliveryResult, Mailer};
use crate::providers::SmtpMailer;
#[must_use = "ProtonBridgeMailer values should be delivered with or stored for later use"]
pub struct ProtonBridgeMailer {
inner: SmtpMailer,
}
impl ProtonBridgeMailer {
#[allow(clippy::new_ret_no_self)]
pub fn new(username: &str, password: &str) -> ProtonBridgeBuilder {
ProtonBridgeBuilder {
host: "127.0.0.1".to_string(),
port: 1025,
username: username.to_string(),
password: password.to_string(),
}
}
}
#[must_use = "ProtonBridgeBuilder configuration methods return a modified builder; chain or assign the returned value"]
pub struct ProtonBridgeBuilder {
host: String,
port: u16,
username: String,
password: String,
}
impl ProtonBridgeBuilder {
pub fn host(mut self, host: &str) -> Self {
self.host = host.to_string();
self
}
pub fn port(mut self, port: u16) -> Self {
self.port = port;
self
}
pub fn build(self) -> Result<ProtonBridgeMailer, MailError> {
let inner = SmtpMailer::new(&self.host, self.port)
.no_tls()
.credentials(&self.username, &self.password)
.build()?;
Ok(ProtonBridgeMailer { inner })
}
}
#[cfg_attr(
all(target_family = "wasm", target_os = "unknown"),
async_trait(?Send)
)]
#[cfg_attr(not(all(target_family = "wasm", target_os = "unknown")), async_trait)]
impl Mailer for ProtonBridgeMailer {
async fn deliver_prepared(&self, email: &PreparedEmail) -> Result<DeliveryResult, MailError> {
self.inner.deliver_prepared(email).await
}
async fn deliver_many_prepared(
&self,
emails: &[PreparedEmail],
) -> Result<Vec<DeliveryResult>, MailError> {
self.inner.deliver_many_prepared(emails).await
}
fn provider_name(&self) -> &'static str {
"protonbridge"
}
}