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 for email categorization
locale: Option<String>
Locale for internationalization
Implementations§
Source§impl EmailOptions
impl EmailOptions
Sourcepub fn new(email_id: impl Into<String>, recipient: Recipient) -> Self
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 userecipient
- 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");
Sourcepub fn with_data(self, data: HashMap<String, Value>) -> Self
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);
Sourcepub fn with_sender(self, sender: Sender) -> Self
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);
Sourcepub fn with_cc(self, cc: Vec<Recipient>) -> Self
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]);
Sourcepub fn with_bcc(self, bcc: Vec<Recipient>) -> Self
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]);
Sourcepub fn with_files(self, files: Vec<Attachment>) -> Self
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]);
Sourcepub fn with_esp_account(self, esp_account: impl Into<String>) -> Self
pub fn with_esp_account(self, esp_account: impl Into<String>) -> Self
Sourcepub fn with_version_name(self, version_name: impl Into<String>) -> Self
pub fn with_version_name(self, version_name: impl Into<String>) -> Self
Sourcepub fn with_headers(self, headers: HashMap<String, String>) -> Self
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);
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()]);
Sourcepub fn with_locale(self, locale: impl Into<String>) -> Self
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
impl Clone for EmailOptions
Source§fn clone(&self) -> EmailOptions
fn clone(&self) -> EmailOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more