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::{
|
use lettre::{
|
||||||
transport::smtp::{authentication::Credentials, AsyncSmtpTransport},
|
|
||||||
AsyncTransport, Message, Tokio1Executor,
|
AsyncTransport, Message, Tokio1Executor,
|
||||||
|
transport::smtp::{AsyncSmtpTransport, authentication::Credentials},
|
||||||
};
|
};
|
||||||
use tracing::{event, Level};
|
use tracing::{Level, event};
|
||||||
|
|
||||||
use crate::consts;
|
use crate::consts;
|
||||||
|
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Parse(lettre::address::AddressError),
|
#[error("Parse error: {0}")]
|
||||||
Smtp(lettre::transport::smtp::Error),
|
Parse(#[from] lettre::address::AddressError),
|
||||||
Email(lettre::error::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<lettre::address::AddressError> for Error {
|
#[error("SMTP error: {0}")]
|
||||||
fn from(error: lettre::address::AddressError) -> Self {
|
Smtp(#[from] lettre::transport::smtp::Error),
|
||||||
Error::Parse(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<lettre::transport::smtp::Error> for Error {
|
#[error("Email error: {0}")]
|
||||||
fn from(error: lettre::transport::smtp::Error) -> Self {
|
Email(#[from] lettre::error::Error),
|
||||||
Error::Smtp(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<lettre::error::Error> for Error {
|
|
||||||
fn from(error: lettre::error::Error) -> Self {
|
|
||||||
Error::Email(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn send_email(
|
pub async fn send_email(
|
||||||
email: &str,
|
email: &str,
|
||||||
message: &str,
|
message: &str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue