pub struct MessageBuilder { /* private fields */ }
Expand description
A builder pattern
type for constructing Message
Use this to construct a Message with the desired data. Make sure you call the ‘build’ method at the end to consume this builder and return the underyling message.
§API Requirements
At least one personalization is required From is required, but handled in the constructor Subject is required, but handled in the constructor
Implementations§
Source§impl MessageBuilder
impl MessageBuilder
Sourcepub fn personalization(self, per: Personalization) -> Self
pub fn personalization(self, per: Personalization) -> Self
Adds a Personalization
to the Message
At least one is required according to the API specification
Use a PersonalizationBuilder
to construct the Personalization
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.personalization(
PersonalizationBuilder::default().build()
);
Sourcepub fn personalizations(self, data: Vec<Personalization>) -> Self
pub fn personalizations(self, data: Vec<Personalization>) -> Self
Overwrites personalializations with input data.
Use this to assign many personalizations at once.
§Examples
let personalizations: Vec<Personalization> = Vec::new();
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.personalizations(personalizations);
Sourcepub fn reply_to(self, contact: Contact) -> Self
pub fn reply_to(self, contact: Contact) -> Self
Adds a reply_to Contact
to the Message
Use a ContactBuilder
to construct the Contact
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.reply_to(
ContactBuilder::new("reply_to@example.com").build()
);
Sourcepub fn content(self, content: Content) -> Self
pub fn content(self, content: Content) -> Self
Adds a Content
to to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.content(
Content::new("text/plain", "Email Body")
);
Sourcepub fn attachment(self, attachment: Attachment) -> Self
pub fn attachment(self, attachment: Attachment) -> Self
Adds an Attachment
to the Message
Use an AttachmentBuilder
to construct the Attachment
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.attachment(
AttachmentBuilder::new(
"SGVsbG8gV29ybGQh",
"file.txt"
).build()
);
Sourcepub fn template_id(self, id: impl Into<String>) -> Self
pub fn template_id(self, id: impl Into<String>) -> Self
Sets the template id the Message
will use.
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.template_id("0001");
Sourcepub fn section<S: Into<String>>(self, key: S, value: S) -> Self
pub fn section<S: Into<String>>(self, key: S, value: S) -> Self
Adds a section key/value pair to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.section("Key", "Value");
Sourcepub fn header<S: Into<String>>(self, key: S, value: S) -> Self
pub fn header<S: Into<String>>(self, key: S, value: S) -> Self
Adds a header key/value pair to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.header("Key", "Value");
Sourcepub fn category(self, category: impl Into<String>) -> Self
pub fn category(self, category: impl Into<String>) -> Self
Adds a category to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.category("Marketing");
Sourcepub fn custom_arg<S: Into<String>>(self, key: S, value: S) -> Self
pub fn custom_arg<S: Into<String>>(self, key: S, value: S) -> Self
Adds a custom arg to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.custom_arg("arg_name", "arg_value");
Sourcepub fn send_at(self, time: i32) -> Self
pub fn send_at(self, time: i32) -> Self
Adds a send_at time to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.send_at(3600);
Sourcepub fn batch_id(self, id: impl Into<String>) -> Self
pub fn batch_id(self, id: impl Into<String>) -> Self
Adds a batch_id to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.batch_id("abc123");
Sourcepub fn asm(self, asm: Asm) -> Self
pub fn asm(self, asm: Asm) -> Self
Adds an Asm
to the Message
Use AsmBuilder
to construct the Asm
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.asm(
AsmBuilder::new(1)
.build()
);
Sourcepub fn ip_pool_name(self, name: impl Into<String>) -> Self
pub fn ip_pool_name(self, name: impl Into<String>) -> Self
Adds the ip_pool_name to the Message
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.ip_pool_name("marketing_pool");
Sourcepub fn mail_settings(self, settings: MailSettings) -> Self
pub fn mail_settings(self, settings: MailSettings) -> Self
Adds MailSettings
to the Message
Use MailSettingsBuilder
to construct the MailSettings
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.mail_settings(
MailSettingsBuilder::default().build()
);
Sourcepub fn tracking_settings(self, settings: TrackingSettings) -> Self
pub fn tracking_settings(self, settings: TrackingSettings) -> Self
Adds TrackingSettings
to the Message
Use TrackingSettingsBuilder
to construct the TrackingSettings
§Examples
let builder = MessageBuilder::new(
ContactBuilder::new("from@example.com").build(),
"Subject Line"
)
.tracking_settings(
TrackingSettingsBuilder::default().build()
);