Skip to main content

MessageBuilder

Struct MessageBuilder 

Source
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

Source

pub fn new() -> Self

Empty builder. All fields default-empty.

Source

pub fn from(self, addr: impl AsRef<str>) -> Self

Set From: (single mailbox).

Source

pub fn reply_to(self, addr: impl AsRef<str>) -> Self

Set Reply-To: (single mailbox).

Source

pub fn to(self, addr: impl AsRef<str>) -> Self

Append one To: recipient.

Source

pub fn cc(self, addr: impl AsRef<str>) -> Self

Append one Cc: recipient.

Source

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.

Source

pub fn subject(self, s: impl Into<String>) -> Self

Set Subject:. Non-ASCII values are RFC 2047 encoded.

Source

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.

Source

pub fn message_id(self, s: impl Into<String>) -> Self

Set Message-ID:. Must include the angle brackets (e.g. <abc@example.com>).

Source

pub fn text_body(self, s: impl Into<String>) -> Self

Set the text/plain body.

Source

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.

Source

pub fn attachment(self, att: Attachment) -> Self

Append an attachment. Adding any attachment promotes the message to multipart/mixed.

Source

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.

Source

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")).

Source

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.

Source

pub fn build(&self) -> Vec<u8>

Render the message to raw bytes.

Trait Implementations§

Source§

impl Clone for MessageBuilder

Source§

fn clone(&self) -> MessageBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MessageBuilder

Source§

fn default() -> MessageBuilder

Returns the “default value” for a type. Read more
Source§

impl Display for MessageBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.