use async_trait::async_trait;
use rusmes_proto::Mail;
#[derive(Debug, Clone)]
pub struct SmtpEnvelope {
pub mail_from: String,
pub rcpt_to: Vec<String>,
}
#[async_trait]
pub trait MailTransport: Send + Sync {
async fn send(&self, envelope: SmtpEnvelope, mail: &Mail) -> anyhow::Result<String>;
async fn send_at(
&self,
envelope: SmtpEnvelope,
mail: &Mail,
at: chrono::DateTime<chrono::Utc>,
) -> anyhow::Result<String>;
async fn cancel(&self, submission_id: &str) -> anyhow::Result<bool>;
}
#[derive(Debug, Default)]
pub struct NullMailTransport;
#[async_trait]
impl MailTransport for NullMailTransport {
async fn send(&self, _envelope: SmtpEnvelope, _mail: &Mail) -> anyhow::Result<String> {
Ok(uuid::Uuid::new_v4().to_string())
}
async fn send_at(
&self,
_envelope: SmtpEnvelope,
_mail: &Mail,
_at: chrono::DateTime<chrono::Utc>,
) -> anyhow::Result<String> {
Ok(uuid::Uuid::new_v4().to_string())
}
async fn cancel(&self, _submission_id: &str) -> anyhow::Result<bool> {
Ok(false)
}
}