feat: include notification recipients in SMTP test email
All checks were successful
CI Pipeline / Rust Format Check (push) Successful in 4s
CI Pipeline / Clippy Lints (push) Successful in 57s
CI Pipeline / Rust Unit Tests (push) Successful in 1m17s
CI Pipeline / Security Audit (push) Successful in 5s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 15s
CI Pipeline / Build .deb & Release (push) Has been skipped
All checks were successful
CI Pipeline / Rust Format Check (push) Successful in 4s
CI Pipeline / Clippy Lints (push) Successful in 57s
CI Pipeline / Rust Unit Tests (push) Successful in 1m17s
CI Pipeline / Security Audit (push) Successful in 5s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 15s
CI Pipeline / Build .deb & Release (push) Has been skipped
This commit is contained in:
@ -619,6 +619,12 @@ async fn test_smtp(
|
|||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| "starttls".to_string());
|
.unwrap_or_else(|| "starttls".to_string());
|
||||||
|
|
||||||
|
let recipients_str = cfg
|
||||||
|
.get("notification_email_recipients")
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let recipients: Vec<String> = serde_json::from_str(&recipients_str).unwrap_or_default();
|
||||||
|
|
||||||
if host.is_empty() || from_addr.is_empty() {
|
if host.is_empty() || from_addr.is_empty() {
|
||||||
return Ok(Json(json!({
|
return Ok(Json(json!({
|
||||||
"success": false,
|
"success": false,
|
||||||
@ -626,13 +632,29 @@ async fn test_smtp(
|
|||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = send_smtp_test(&host, port, &username, &password, &from_addr, &tls_mode).await;
|
let result = send_smtp_test(
|
||||||
|
&host,
|
||||||
|
port,
|
||||||
|
&username,
|
||||||
|
&password,
|
||||||
|
&from_addr,
|
||||||
|
&tls_mode,
|
||||||
|
&recipients,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => Ok(Json(json!({
|
Ok(()) => {
|
||||||
"success": true,
|
let recipient_info = if recipients.is_empty() {
|
||||||
"message": "Test email sent successfully"
|
String::new()
|
||||||
}))),
|
} else {
|
||||||
|
format!(" and {} recipient(s)", recipients.len())
|
||||||
|
};
|
||||||
|
Ok(Json(json!({
|
||||||
|
"success": true,
|
||||||
|
"message": format!("Test email sent successfully to from address{}", recipient_info)
|
||||||
|
})))
|
||||||
|
},
|
||||||
Err(e) => Ok(Json(json!({
|
Err(e) => Ok(Json(json!({
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": format!("Failed to send test email: {}", e)
|
"message": format!("Failed to send test email: {}", e)
|
||||||
@ -647,17 +669,35 @@ async fn send_smtp_test(
|
|||||||
password: &str,
|
password: &str,
|
||||||
from_addr: &str,
|
from_addr: &str,
|
||||||
tls_mode: &str,
|
tls_mode: &str,
|
||||||
|
recipients: &[String],
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let from_mailbox: Mailbox = from_addr
|
let from_mailbox: Mailbox = from_addr
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|e| format!("Invalid from address: {}", e))?;
|
.map_err(|e| format!("Invalid from address: {}", e))?;
|
||||||
|
|
||||||
let email = Message::builder()
|
let mut builder = Message::builder()
|
||||||
.from(from_mailbox.clone())
|
.from(from_mailbox.clone())
|
||||||
.to(from_mailbox)
|
.to(from_mailbox);
|
||||||
|
|
||||||
|
for recipient in recipients {
|
||||||
|
if let Ok(addr) = recipient.parse() {
|
||||||
|
builder = builder.bcc(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let body = if recipients.is_empty() {
|
||||||
|
"This is a test email from Linux Patch Manager.".to_string()
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"This is a test email from Linux Patch Manager.\n\nSent to: {}",
|
||||||
|
recipients.join(", ")
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let email = builder
|
||||||
.subject("Linux Patch Manager — SMTP Test")
|
.subject("Linux Patch Manager — SMTP Test")
|
||||||
.header(ContentType::TEXT_PLAIN)
|
.header(ContentType::TEXT_PLAIN)
|
||||||
.body("This is a test email from Linux Patch Manager.".to_string())
|
.body(body)
|
||||||
.map_err(|e| format!("Failed to build email: {}", e))?;
|
.map_err(|e| format!("Failed to build email: {}", e))?;
|
||||||
|
|
||||||
let result = match tls_mode {
|
let result = match tls_mode {
|
||||||
|
|||||||
Reference in New Issue
Block a user