Use thiserror crate for email (instead of manually implementing all 'From' traits)
This commit is contained in:
parent
4ddc12ba28
commit
b8a8af3979
1 changed files with 9 additions and 24 deletions
|
|
@ -1,37 +1,22 @@
|
|||
use derive_more::Display;
|
||||
use lettre::{
|
||||
transport::smtp::{authentication::Credentials, AsyncSmtpTransport},
|
||||
AsyncTransport, Message, Tokio1Executor,
|
||||
transport::smtp::{AsyncSmtpTransport, authentication::Credentials},
|
||||
};
|
||||
use tracing::{event, Level};
|
||||
use tracing::{Level, event};
|
||||
|
||||
use crate::consts;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
Parse(lettre::address::AddressError),
|
||||
Smtp(lettre::transport::smtp::Error),
|
||||
Email(lettre::error::Error),
|
||||
}
|
||||
#[error("Parse error: {0}")]
|
||||
Parse(#[from] lettre::address::AddressError),
|
||||
|
||||
impl From<lettre::address::AddressError> for Error {
|
||||
fn from(error: lettre::address::AddressError) -> Self {
|
||||
Error::Parse(error)
|
||||
}
|
||||
}
|
||||
#[error("SMTP error: {0}")]
|
||||
Smtp(#[from] lettre::transport::smtp::Error),
|
||||
|
||||
impl From<lettre::transport::smtp::Error> for Error {
|
||||
fn from(error: lettre::transport::smtp::Error) -> Self {
|
||||
Error::Smtp(error)
|
||||
#[error("Email error: {0}")]
|
||||
Email(#[from] lettre::error::Error),
|
||||
}
|
||||
}
|
||||
|
||||
impl From<lettre::error::Error> for Error {
|
||||
fn from(error: lettre::error::Error) -> Self {
|
||||
Error::Email(error)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send_email(
|
||||
email: &str,
|
||||
message: &str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue