use thiserror::Error;
#[derive(Debug, Error)]
pub enum EmailError {
#[error("email must have at least one recipient")]
NoRecipients,
#[error("email must have a from address")]
NoSender,
#[error("email must have a subject")]
NoSubject,
#[error("email must have either text or HTML content")]
NoContent,
#[error("invalid email address: {0}")]
InvalidAddress(String),
#[error("failed to render email template: {0}")]
TemplateError(#[from] askama::Error),
#[error("SMTP error: {0}")]
SmtpError(String),
#[error("AWS SES error: {0}")]
AwsSesError(String),
#[error("email configuration error: {0}")]
ConfigError(String),
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),
#[error("serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
}
impl EmailError {
#[must_use]
pub fn smtp<T: Into<String>>(msg: T) -> Self {
Self::SmtpError(msg.into())
}
#[must_use]
pub fn aws_ses<T: Into<String>>(msg: T) -> Self {
Self::AwsSesError(msg.into())
}
#[must_use]
pub fn config<T: Into<String>>(msg: T) -> Self {
Self::ConfigError(msg.into())
}
}