Skip to main content

aster_forge_mail/
lib.rs

1//! Shared mail infrastructure helpers for Aster services.
2//!
3//! This crate intentionally does not own product templates, recipients, audit
4//! records, user context, SMTP configuration keys, or database entities. It only
5//! provides small mechanics that recur around mail outbox dispatch: dispatch
6//! counters, retry delay selection, error truncation, and best-effort retry when
7//! persisting a successful SMTP delivery. It also provides a product-neutral
8//! template registry and placeholder rendering helpers for services that own
9//! their own template codes and payloads.
10#![cfg_attr(
11    not(test),
12    deny(
13        clippy::unwrap_used,
14        clippy::unreachable,
15        clippy::expect_used,
16        clippy::panic,
17        clippy::unimplemented,
18        clippy::todo
19    )
20)]
21
22#[cfg(feature = "runtime-component")]
23mod component;
24pub mod config;
25pub mod message;
26pub mod outbox;
27pub mod sender;
28pub mod template;
29
30/// Stable component name used for mail outbox lifecycle handling.
31pub const MAIL_OUTBOX_COMPONENT: &str = "mail_outbox";
32
33#[cfg(feature = "runtime-component")]
34pub use component::{MAIL_OUTBOX_DRAIN_SHUTDOWN_PHASE, mail_outbox_component};
35pub use config::{
36    DEFAULT_MAIL_SECURITY, DEFAULT_MAIL_SMTP_PORT, MAIL_TEMPLATE_MAX_BODY_LEN,
37    MAIL_TEMPLATE_MAX_SUBJECT_LEN, MailConfigError, MailConfigResult, MailRuntimeSettings,
38    normalize_mail_address_config_value, normalize_mail_name_config_value,
39    normalize_mail_security_config_value, normalize_mail_template_body_config_value,
40    normalize_mail_template_subject_config_value, normalize_smtp_host_config_value,
41    normalize_smtp_port_config_value, parse_smtp_port,
42};
43pub use message::{MailMessage, MailRecipient};
44pub use outbox::{
45    DEFAULT_ERROR_MAX_LEN, DEFAULT_MARK_SENT_RETRY_DELAYS_MS, DispatchStats,
46    MailOutboxDeliveryFailureDecision, MailOutboxDispatchConfig, MailOutboxDispatchContext,
47    MailOutboxDispatchRow, MailOutboxRetryPolicy, MailOutboxStatus, MailTemplateCode,
48    StoredMailPayload, dispatch_mail_outbox, drain_mail_outbox, retry_mark_sent, truncate_error,
49};
50pub use sender::{
51    DEFAULT_SMTP_SEND_TIMEOUT_SECS, MailDeliveryError, MailSendResult, MailSender,
52    MemoryMailSender, SmtpMailSender, memory_sender, memory_sender_ref, send_rendered_with,
53    smtp_sender,
54};
55pub use template::{
56    MailTemplateCatalog, MailTemplateCatalogBuilder, MailTemplateDefinition, MailTemplateRegistrar,
57    MailTemplateRegistry, MailTemplateRegistryError, RenderedMail, TemplatePlaceholderSet,
58    TemplateVariableGroup, TemplateVariableItem, TemplateVariableSpec, escape_html, html_to_text,
59    render_placeholders, render_template,
60};