gitdataai/libs/config/smtp.rs
2026-04-14 19:02:01 +08:00

53 lines
1.5 KiB
Rust

use crate::AppConfig;
impl AppConfig {
pub fn smtp_host(&self) -> anyhow::Result<String> {
if let Some(host) = self.env.get("APP_SMTP_HOST") {
return Ok(host.to_string());
}
Err(anyhow::anyhow!("APP_SMTP_HOST not found"))
}
pub fn smtp_port(&self) -> anyhow::Result<u16> {
if let Some(port) = self.env.get("APP_SMTP_PORT") {
return Ok(port.parse::<u16>()?);
}
Ok(587)
}
pub fn smtp_username(&self) -> anyhow::Result<String> {
if let Some(username) = self.env.get("APP_SMTP_USERNAME") {
return Ok(username.to_string());
}
Err(anyhow::anyhow!("APP_SMTP_USERNAME not found"))
}
pub fn smtp_password(&self) -> anyhow::Result<String> {
if let Some(password) = self.env.get("APP_SMTP_PASSWORD") {
return Ok(password.to_string());
}
Err(anyhow::anyhow!("APP_SMTP_PASSWORD not found"))
}
pub fn smtp_from(&self) -> anyhow::Result<String> {
if let Some(from) = self.env.get("APP_SMTP_FROM") {
return Ok(from.to_string());
}
Err(anyhow::anyhow!("APP_SMTP_FROM not found"))
}
pub fn smtp_tls(&self) -> anyhow::Result<bool> {
if let Some(tls) = self.env.get("APP_SMTP_TLS") {
return Ok(tls.parse::<bool>()?);
}
Ok(true)
}
pub fn smtp_timeout(&self) -> anyhow::Result<u64> {
if let Some(timeout) = self.env.get("APP_SMTP_TIMEOUT") {
return Ok(timeout.parse::<u64>()?);
}
Ok(30)
}
}