mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-09 14:21:49 +00:00
notify: sendmail: query default author/mailfrom from context
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
c5f91aa1c8
commit
da2e7b8da9
@ -3,6 +3,8 @@ use std::fmt::Debug;
|
|||||||
|
|
||||||
pub trait Context: Send + Sync + Debug {
|
pub trait Context: Send + Sync + Debug {
|
||||||
fn lookup_email_for_user(&self, user: &str) -> Option<String>;
|
fn lookup_email_for_user(&self, user: &str) -> Option<String>;
|
||||||
|
fn default_sendmail_author(&self) -> String;
|
||||||
|
fn default_sendmail_from(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CONTEXT: OnceCell<&'static dyn Context> = OnceCell::new();
|
static CONTEXT: OnceCell<&'static dyn Context> = OnceCell::new();
|
||||||
|
@ -112,9 +112,17 @@ impl Endpoint for SendmailEndpoint {
|
|||||||
let text_part =
|
let text_part =
|
||||||
renderer::render_template(TemplateRenderer::Plaintext, ¬ification.body, properties)?;
|
renderer::render_template(TemplateRenderer::Plaintext, ¬ification.body, properties)?;
|
||||||
|
|
||||||
// proxmox_sys::email::sendmail will set the author to
|
let author = self
|
||||||
// "Proxmox Backup Server" if it is not set.
|
.config
|
||||||
let author = self.config.author.as_deref().or(Some(""));
|
.author
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| context().default_sendmail_author());
|
||||||
|
|
||||||
|
let mailfrom = self
|
||||||
|
.config
|
||||||
|
.from_address
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| context().default_sendmail_from());
|
||||||
|
|
||||||
let recipients_str: Vec<&str> = recipients.iter().map(String::as_str).collect();
|
let recipients_str: Vec<&str> = recipients.iter().map(String::as_str).collect();
|
||||||
|
|
||||||
@ -123,8 +131,8 @@ impl Endpoint for SendmailEndpoint {
|
|||||||
&subject,
|
&subject,
|
||||||
Some(&text_part),
|
Some(&text_part),
|
||||||
Some(&html_part),
|
Some(&html_part),
|
||||||
self.config.from_address.as_deref(),
|
Some(&mailfrom),
|
||||||
author,
|
Some(&author),
|
||||||
)
|
)
|
||||||
.map_err(|err| Error::NotifyFailed(self.config.name.clone(), err.into()))
|
.map_err(|err| Error::NotifyFailed(self.config.name.clone(), err.into()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user