Email

Struct Email 

Source
pub struct Email {
Show 13 fields pub from: Option<Address>, pub to: Vec<Address>, pub cc: Vec<Address>, pub bcc: Vec<Address>, pub reply_to: Vec<Address>, pub subject: String, pub text_body: Option<String>, pub html_body: Option<String>, pub attachments: Vec<Attachment>, pub headers: HashMap<String, String>, pub assigns: HashMap<String, Value>, pub private: HashMap<String, Value>, pub provider_options: HashMap<String, Value>,
}
Expand description

An email message.

Use the builder pattern to construct emails:

use missive::Email;

let email = Email::new()
    .from("sender@example.com")
    .to("recipient@example.com")
    .subject("Hello!")
    .text_body("Plain text content")
    .html_body("<h1>HTML content</h1>");

§Fields

  • from, to, cc, bcc - Addresses
  • reply_to - Reply-to addresses (supports multiple)
  • subject, text_body, html_body - Content
  • attachments - File attachments
  • headers - Custom email headers
  • assigns - Template variables (for use with templating systems)
  • private - Private storage for libraries/frameworks
  • provider_options - Provider-specific options (tags, templates, etc.)

Fields§

§from: Option<Address>

Sender address

§to: Vec<Address>

Primary recipients

§cc: Vec<Address>

Carbon copy recipients

§bcc: Vec<Address>

Blind carbon copy recipients

§reply_to: Vec<Address>

Reply-to addresses (supports multiple)

§subject: String

Email subject line

§text_body: Option<String>

Plain text body

§html_body: Option<String>

HTML body

§attachments: Vec<Attachment>

File attachments

§headers: HashMap<String, String>

Custom email headers

§assigns: HashMap<String, Value>

Template variables for use with templating systems.

§private: HashMap<String, Value>

Private storage for libraries/frameworks (e.g., template paths, metadata).

§provider_options: HashMap<String, Value>

Provider-specific options (e.g., tracking, tags, templates)

Implementations§

Source§

impl Email

Source

pub fn new() -> Self

Create a new empty email.

Source

pub fn from(self, addr: impl ToAddress) -> Self

Set the sender address.

Accepts anything that implements ToAddress:

  • "email@example.com" - just email
  • ("Name", "email@example.com") - name and email
  • Custom types that implement ToAddress
Source

pub fn to(self, addr: impl ToAddress) -> Self

Add a recipient.

Can be called multiple times to add multiple recipients. Accepts anything that implements ToAddress.

Source

pub fn put_to(self, addrs: Vec<Address>) -> Self

Replace all recipients.

Source

pub fn cc(self, addr: impl ToAddress) -> Self

Add a CC recipient. Accepts anything that implements ToAddress.

Source

pub fn put_cc(self, addrs: Vec<Address>) -> Self

Replace all CC recipients.

Source

pub fn bcc(self, addr: impl ToAddress) -> Self

Add a BCC recipient. Accepts anything that implements ToAddress.

Source

pub fn put_bcc(self, addrs: Vec<Address>) -> Self

Replace all BCC recipients.

Source

pub fn reply_to(self, addr: impl ToAddress) -> Self

Add a reply-to address.

Can be called multiple times to add multiple reply-to addresses. Accepts anything that implements ToAddress.

Source

pub fn put_reply_to(self, addrs: Vec<Address>) -> Self

Replace all reply-to addresses.

Source

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

Set the subject line.

Source

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

Set the plain text body.

Source

pub fn html_body(self, body: impl Into<String>) -> Self

Set the HTML body.

Source

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

Add an attachment.

Source

pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self

Add a custom header.

Source

pub fn provider_option( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self

Set a provider-specific option.

These are passed to the adapter for provider-specific features (e.g., SendGrid categories, Postmark tags, Resend templates).

§Example
Email::new()
    .provider_option("template_id", "welcome-email")
    .provider_option("tags", vec!["signup", "welcome"])
Source

pub fn assign(self, key: impl Into<String>, value: impl Into<Value>) -> Self

Store a template variable for use with templating systems.

§Example
Email::new()
    .assign("username", "alice")
    .assign("action_url", "https://example.com/verify")
Source

pub fn put_private( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self

Store a private value for frameworks/libraries.

Reserved for framework use (e.g., template paths, metadata).

§Example
Email::new()
    .put_private("template_path", "emails/welcome.html")
    .put_private("sent_at", chrono::Utc::now().to_rfc3339())
Source

pub fn is_valid(&self) -> bool

Check if the email has all required fields for sending.

Source

pub fn all_recipients(&self) -> Vec<&Address>

Get all recipients (to + cc + bcc).

Source

pub fn has_attachments(&self) -> bool

Check if the email has any attachments.

Source

pub fn inline_attachments(&self) -> Vec<&Attachment>

Get inline attachments only.

Source

pub fn regular_attachments(&self) -> Vec<&Attachment>

Get regular (non-inline) attachments only.

Trait Implementations§

Source§

impl Clone for Email

Source§

fn clone(&self) -> Email

Returns a duplicate 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 Debug for Email

Source§

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

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

impl Default for Email

Source§

fn default() -> Email

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

impl<'de> Deserialize<'de> for Email

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Email

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Email

§

impl RefUnwindSafe for Email

§

impl Send for Email

§

impl Sync for Email

§

impl Unpin for Email

§

impl UnwindSafe for Email

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,