chore(project): initialize project with core configuration and dependencies
- Add .gitignore and .env.example files for project setup - Create build script for proto compilation with tonic-prost - Generate Cargo.lock with all project dependencies - Configure project structure and ignore patterns for development environment
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use lettre::{AsyncSmtpTransport, AsyncTransport, Tokio1Executor};
|
||||
|
||||
pub use crate::error::EmailError;
|
||||
use crate::{
|
||||
config::SmtpConfig, email_build::build_message_from_parts, pb::email::v1::SendEmailRequest,
|
||||
queue::EmailJob,
|
||||
};
|
||||
|
||||
pub(crate) type Mailer = AsyncSmtpTransport<Tokio1Executor>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EmailSender {
|
||||
config: Arc<SmtpConfig>,
|
||||
mailer: Mailer,
|
||||
}
|
||||
|
||||
impl EmailSender {
|
||||
pub fn new(config: SmtpConfig) -> Result<Self, EmailError> {
|
||||
let mailer = crate::email_build::build_mailer(&config)?;
|
||||
Ok(Self {
|
||||
config: Arc::new(config),
|
||||
mailer,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn send(&self, request: &SendEmailRequest) -> Result<(), EmailError> {
|
||||
let message = build_message_from_parts(&self.config, request)?;
|
||||
self.mailer
|
||||
.send(message)
|
||||
.await
|
||||
.map_err(|e| EmailError::Send(e.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn send_job(&self, job: &EmailJob) -> Result<(), EmailError> {
|
||||
self.send(&job.request).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user