pub struct MessageBuilder<'x> {
    pub headers: Vec<(Cow<'x, str>, HeaderType<'x>)>,
    pub html_body: Option<MimePart<'x>>,
    pub text_body: Option<MimePart<'x>>,
    pub attachments: Option<Vec<MimePart<'x>>>,
    pub body: Option<MimePart<'x>>,
}
Expand description

Builds an RFC5322 compliant MIME email message.

Fields§

§headers: Vec<(Cow<'x, str>, HeaderType<'x>)>§html_body: Option<MimePart<'x>>§text_body: Option<MimePart<'x>>§attachments: Option<Vec<MimePart<'x>>>§body: Option<MimePart<'x>>

Implementations§

source§

impl<'x> MessageBuilder<'x>

source

pub fn new() -> Self

Create a new MessageBuilder.

source

pub fn message_id(self, value: impl Into<MessageId<'x>>) -> Self

Set the Message-ID header. If no Message-ID header is set, one will be generated automatically.

source

pub fn in_reply_to(self, value: impl Into<MessageId<'x>>) -> Self

Set the In-Reply-To header.

source

pub fn references(self, value: impl Into<MessageId<'x>>) -> Self

Set the References header.

source

pub fn sender(self, value: impl Into<Address<'x>>) -> Self

Set the Sender header.

source

pub fn from(self, value: impl Into<Address<'x>>) -> Self

Set the From header.

source

pub fn to(self, value: impl Into<Address<'x>>) -> Self

Set the To header.

source

pub fn cc(self, value: impl Into<Address<'x>>) -> Self

Set the Cc header.

source

pub fn bcc(self, value: impl Into<Address<'x>>) -> Self

Set the Bcc header.

source

pub fn reply_to(self, value: impl Into<Address<'x>>) -> Self

Set the Reply-To header.

source

pub fn subject(self, value: impl Into<Text<'x>>) -> Self

Set the Subject header.

source

pub fn date(self, value: impl Into<Date>) -> Self

Set the Date header. If no Date header is set, one will be generated automatically.

source

pub fn header( self, header: impl Into<Cow<'x, str>>, value: impl Into<HeaderType<'x>> ) -> Self

Add a custom header.

source

pub fn headers<T, U, V>(self, header: T, values: U) -> Selfwhere T: Into<Cow<'x, str>>, U: IntoIterator<Item = V>, V: Into<HeaderType<'x>>,

Set custom headers.

source

pub fn text_body(self, value: impl Into<Cow<'x, str>>) -> Self

Set the plain text body of the message. Note that only one plain text body per message can be set using this function. To build more complex MIME body structures, use the body method instead.

source

pub fn html_body(self, value: impl Into<Cow<'x, str>>) -> Self

Set the HTML body of the message. Note that only one HTML body per message can be set using this function. To build more complex MIME body structures, use the body method instead.

source

pub fn attachment( self, content_type: impl Into<ContentType<'x>>, filename: impl Into<Cow<'x, str>>, value: impl Into<BodyPart<'x>> ) -> Self

Add a binary attachment to the message.

source

pub fn inline( self, content_type: impl Into<ContentType<'x>>, cid: impl Into<Cow<'x, str>>, value: impl Into<BodyPart<'x>> ) -> Self

Add an inline binary to the message.

source

pub fn body(self, value: MimePart<'x>) -> Self

Set a custom MIME body structure.

source

pub fn write_to(self, output: impl Write) -> Result<()>

Build the message.

source

pub fn write_body(self, output: impl Write) -> Result<()>

Write the message body without headers.

source

pub fn write_to_vec(self) -> Result<Vec<u8>>

Build message to a Vec.

source

pub fn write_to_string(self) -> Result<String>

Build message to a String.

Trait Implementations§

source§

impl<'x> Clone for MessageBuilder<'x>

source§

fn clone(&self) -> MessageBuilder<'x>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'x> Debug for MessageBuilder<'x>

source§

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

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

impl<'x> Default for MessageBuilder<'x>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'x> RefUnwindSafe for MessageBuilder<'x>

§

impl<'x> Send for MessageBuilder<'x>

§

impl<'x> Sync for MessageBuilder<'x>

§

impl<'x> Unpin for MessageBuilder<'x>

§

impl<'x> UnwindSafe for MessageBuilder<'x>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.