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

Builds an RFC5322 compliant MIME email message.

Fields§

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

Implementations§

§

impl<'x> MessageBuilder<'x>

pub fn new() -> MessageBuilder<'x>

Create a new MessageBuilder.

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

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

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

Set the In-Reply-To header.

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

Set the References header.

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

Set the Sender header.

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

Set the From header.

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

Set the To header.

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

Set the Cc header.

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

Set the Bcc header.

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

Set the Reply-To header.

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

Set the Subject header.

pub fn date(self, value: impl Into<Date>) -> MessageBuilder<'x>

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

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

Add a custom header.

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

Set custom headers.

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

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.

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

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.

pub fn binary_attachment( self, content_type: impl Into<Cow<'x, str>>, filename: impl Into<Cow<'x, str>>, value: impl Into<Cow<'x, [u8]>> ) -> MessageBuilder<'x>

Add a binary attachment to the message.

pub fn text_attachment( self, content_type: impl Into<Cow<'x, str>>, filename: impl Into<Cow<'x, str>>, value: impl Into<Cow<'x, str>> ) -> MessageBuilder<'x>

Add a text attachment to the message.

pub fn binary_inline( self, content_type: impl Into<Cow<'x, str>>, cid: impl Into<Cow<'x, str>>, value: impl Into<Cow<'x, [u8]>> ) -> MessageBuilder<'x>

Add an inline binary to the message.

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

Set a custom MIME body structure.

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

Build the message.

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

Write the message body without headers.

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

Build message to a Vec.

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

Build message to a String.

Trait Implementations§

§

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

§

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
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> MessageBuilder<'x>

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

impl<'x, 'y> IntoMessage<'x> for MessageBuilder<'y>

§

fn into_message(self) -> Result<Message<'x>, Error>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more