Struct MessageBuilder

Source
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() -> MessageBuilder<'x>

Create a new MessageBuilder.

Source

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.

Source

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

Set the In-Reply-To header.

Source

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

Set the References header.

Source

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

Set the Sender header.

Source

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

Set the From header.

Source

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

Set the To header.

Source

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

Set the Cc header.

Source

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

Set the Bcc header.

Source

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

Set the Reply-To header.

Source

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

Set the Subject header.

Source

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.

Source

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

Add a custom header.

Source

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.

Source

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.

Source

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.

Source

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

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>>, ) -> MessageBuilder<'x>

Add an inline binary to the message.

Source

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

Set a custom MIME body structure.

Source

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

Build the message.

Source

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

Write the message body without headers.

Source

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

Build message to a Vec.

Source

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

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<(), Error>

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

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

Source§

fn default() -> MessageBuilder<'x>

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

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

Auto Trait Implementations§

§

impl<'x> Freeze for MessageBuilder<'x>

§

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 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> 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 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, 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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,