pub struct MessageBuilder { /* private fields */ }Expand description
Builder for outbound RFC 5322 messages.
Construction is chain-style: MessageBuilder::new().from(..).to(..).subject(..).
Call build for the raw bytes or use the
[Display] impl for a UTF-8 string view.
Implementations§
Source§impl MessageBuilder
impl MessageBuilder
Sourcepub fn bcc(self, addr: impl AsRef<str>) -> Self
pub fn bcc(self, addr: impl AsRef<str>) -> Self
Append one Bcc: recipient. Bcc is emitted into the message
body so a downstream MTA strips it before relay; callers
emitting via the SMTP envelope should NOT add the bcc here.
Sourcepub fn subject(self, s: impl Into<String>) -> Self
pub fn subject(self, s: impl Into<String>) -> Self
Set Subject:. Non-ASCII values are RFC 2047 encoded.
Sourcepub fn date(self, s: impl Into<String>) -> Self
pub fn date(self, s: impl Into<String>) -> Self
Set Date:. If omitted, build() fills in the current UTC
in RFC 5322 §3.3 format.
Sourcepub fn message_id(self, s: impl Into<String>) -> Self
pub fn message_id(self, s: impl Into<String>) -> Self
Set Message-ID:. Must include the angle brackets
(e.g. <abc@example.com>).
Sourcepub fn html_body(self, s: impl Into<String>) -> Self
pub fn html_body(self, s: impl Into<String>) -> Self
Set the text/html body. If both text_body and html_body
are set, the message becomes multipart/alternative.
Sourcepub fn attachment(self, att: Attachment) -> Self
pub fn attachment(self, att: Attachment) -> Self
Append an attachment. Adding any attachment promotes the
message to multipart/mixed.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add an arbitrary extra header. Use sparingly — almost every standard header has a typed setter above. Header values are folded and encoded-word-protected automatically.
Sourcepub fn report_type(self, kind: impl Into<String>) -> Self
pub fn report_type(self, kind: impl Into<String>) -> Self
Set the multipart report-type per RFC 6522. With this set,
any multipart container the builder emits uses
multipart/report; report-type=<value>; boundary=... instead
of multipart/mixed. Required for DSN
(report_type("delivery-status")), MDN
(report_type("disposition-notification")), and TLSRPT
(report_type("tlsrpt")).
Sourcepub fn build_strict(&self) -> Result<Vec<u8>, LintError>
pub fn build_strict(&self) -> Result<Vec<u8>, LintError>
Render the message to raw bytes after running the strict-mode invariant checks. Returns the first failure if any.
Use this when you want compile-time-level confidence that the outbound bytes meet RFC 5322 / 2045 invariants — e.g. before handing them to a DKIM signer that would silently sign a non-compliant message, or before publishing them as a stalwart-grade artifact in a corpus.
Trait Implementations§
Source§impl Clone for MessageBuilder
impl Clone for MessageBuilder
Source§fn clone(&self) -> MessageBuilder
fn clone(&self) -> MessageBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more