Struct EmailOptions

Source
pub struct EmailOptions {
    pub email_id: String,
    pub recipient: Recipient,
    pub data: Option<HashMap<String, Value>>,
    pub sender: Option<Sender>,
    pub cc: Option<Vec<Recipient>>,
    pub bcc: Option<Vec<Recipient>>,
    pub files: Option<Vec<Attachment>>,
    pub esp_account: Option<String>,
    pub version_name: Option<String>,
    pub headers: Option<HashMap<String, String>>,
    pub tags: Option<Vec<String>>,
    pub locale: Option<String>,
}
Expand description

Represents the complete set of options for sending an email through SendWithUs.

This struct is the primary interface for configuring emails to be sent using the SendWithUs API. It includes the template ID, recipient information, dynamic data, and various optional settings like CC/BCC recipients, attachments, and more.

Uses the builder pattern to create and configure email options in a fluent interface.

§Examples

use send_with_us::types::{EmailOptions, Recipient, Sender};
use std::collections::HashMap;
use serde_json::json;

let recipient = Recipient::new("user@example.com").with_name("User Name");
let email = EmailOptions::new("template-id-123", recipient);

let recipient = Recipient::new("customer@example.com").with_name("Customer");
let sender = Sender::new("support@company.com").with_name("Support Team");

let mut data = HashMap::new();
data.insert("name".to_string(), json!("John"));
data.insert("order_id".to_string(), json!("12345"));

let email = EmailOptions::new("template-id-123", recipient)
  .with_data(data)
  .with_sender(sender)
  .with_cc(vec![Recipient::new("manager@company.com")])
  .with_locale("en-US")
  .with_tags(vec!["welcome".to_string(), "new-user".to_string()]);

Fields§

§email_id: String

Email template ID

§recipient: Recipient

Email recipient

§data: Option<HashMap<String, Value>>

Dynamic email data for template variables

§sender: Option<Sender>

Email sender information

§cc: Option<Vec<Recipient>>

CC recipients

§bcc: Option<Vec<Recipient>>

BCC recipients

§files: Option<Vec<Attachment>>

File attachments

§esp_account: Option<String>

ESP account identifier

§version_name: Option<String>

Template version name

§headers: Option<HashMap<String, String>>

Custom email headers

§tags: Option<Vec<String>>

Tags for email categorization

§locale: Option<String>

Locale for internationalization

Implementations§

Source§

impl EmailOptions

Source

pub fn new(email_id: impl Into<String>, recipient: Recipient) -> Self

Creates new email options with a template ID and recipient.

§Arguments
  • email_id - The SendWithUs template ID to use
  • recipient - The primary recipient of the email
§Returns

A new EmailOptions instance with the specified template and recipient

§Examples
use send_with_us::types::{EmailOptions, Recipient};

let recipient = Recipient::new("user@example.com");
let options = EmailOptions::new("template-123", recipient);

assert_eq!(options.email_id, "template-123");
Source

pub fn with_data(self, data: HashMap<String, Value>) -> Self

Sets dynamic data for the email template.

This data is used to replace variables in the template with actual values.

§Arguments
  • data - HashMap of template variable names to values
§Returns

Self with the added template data for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};
use std::collections::HashMap;
use serde_json::json;

let recipient = Recipient::new("user@example.com");

let mut data = HashMap::new();
data.insert("first_name".to_string(), json!("John"));
data.insert("last_name".to_string(), json!("Doe"));
data.insert("items".to_string(), json!(["item1", "item2"]));

let options = EmailOptions::new("template-123", recipient)
    .with_data(data);
Source

pub fn with_sender(self, sender: Sender) -> Self

Sets the sender information for the email.

§Arguments
  • sender - The sender information
§Returns

Self with the added sender for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient, Sender};

let recipient = Recipient::new("user@example.com");
let sender = Sender::new("support@company.com")
    .with_name("Support Team");

let options = EmailOptions::new("template-123", recipient)
    .with_sender(sender);
Source

pub fn with_cc(self, cc: Vec<Recipient>) -> Self

Adds CC (carbon copy) recipients to the email.

§Arguments
  • cc - Vector of CC recipients
§Returns

Self with the added CC recipients for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};

let recipient = Recipient::new("user@example.com");
let cc1 = Recipient::new("manager@company.com");
let cc2 = Recipient::new("support@company.com").with_name("Support Team");

let options = EmailOptions::new("template-123", recipient)
    .with_cc(vec![cc1, cc2]);
Source

pub fn with_bcc(self, bcc: Vec<Recipient>) -> Self

Adds BCC (blind carbon copy) recipients to the email.

§Arguments
  • bcc - Vector of BCC recipients
§Returns

Self with the added BCC recipients for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};

let recipient = Recipient::new("user@example.com");
let bcc = Recipient::new("archive@company.com");

let options = EmailOptions::new("template-123", recipient)
    .with_bcc(vec![bcc]);
Source

pub fn with_files(self, files: Vec<Attachment>) -> Self

Adds file attachments to the email.

§Arguments
  • files - Vector of file attachments
§Returns

Self with the added attachments for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};
use send_with_us::Attachment;

let recipient = Recipient::new("user@example.com");

// In a real application, you would load these attachments from files
let attachment = Attachment::from_bytes(b"test content", "test.txt");

let options = EmailOptions::new("template-123", recipient)
  .with_files(vec![attachment]);
Source

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

Sets the ESP (Email Service Provider) account to use.

Some SendWithUs configurations allow for multiple ESP integrations. This option specifies which one to use for this email.

§Arguments
  • esp_account - The ESP account identifier
§Returns

Self with the ESP account set for method chaining

Source

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

Sets a specific template version to use.

§Arguments
  • version_name - The template version name
§Returns

Self with the template version set for method chaining

Source

pub fn with_headers(self, headers: HashMap<String, String>) -> Self

Sets custom email headers.

§Arguments
  • headers - HashMap of header names to values
§Returns

Self with the custom headers set for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};
use std::collections::HashMap;

let recipient = Recipient::new("user@example.com");

let mut headers = HashMap::new();
headers.insert("X-Custom-Header".to_string(), "Custom Value".to_string());
headers.insert("X-Priority".to_string(), "1".to_string());

let options = EmailOptions::new("template-123", recipient)
  .with_headers(headers);
Source

pub fn with_tags(self, tags: Vec<String>) -> Self

Adds tags to the email for categorization and tracking.

§Arguments
  • tags - Vector of tag strings
§Returns

Self with the tags added for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};

let recipient = Recipient::new("user@example.com");

let options = EmailOptions::new("template-123", recipient)
  .with_tags(vec!["welcome".to_string(), "new-user".to_string()]);
Source

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

Sets the locale for internationalization.

This can be used to select language-specific template versions.

§Arguments
  • locale - The locale code (e.g., “en-US”, “fr-CA”)
§Returns

Self with the locale set for method chaining

§Examples
use send_with_us::types::{EmailOptions, Recipient};

let recipient = Recipient::new("user@example.com");

let options = EmailOptions::new("template-123", recipient)
  .with_locale("fr-CA");

Trait Implementations§

Source§

impl Clone for EmailOptions

Source§

fn clone(&self) -> EmailOptions

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 Debug for EmailOptions

Source§

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

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

impl<'de> Deserialize<'de> for EmailOptions

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 PartialEq for EmailOptions

Source§

fn eq(&self, other: &EmailOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for EmailOptions

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

impl StructuralPartialEq for EmailOptions

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> 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>,

Source§

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