Struct MessageBuilder

Source
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

Source

pub fn new(from: Contact, subject: impl Into<String>) -> Self

Creates a MessageBuilder.

§Parameters

from: Contact subject: impl Into

§Examples

let builder = MessageBuilder::new(
        ContactBuilder::new("from@example.com").build(),
        "Subject Line"
    );
Source

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()
    );
Source

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);
Source

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()
    );
Source

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")
        );
Source

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()
        );
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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);
Source

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");
Source

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()
        );
Source

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");
Source

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()
        );
Source

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()
        );
Source

pub fn build(self) -> Message

Consumes the MessageBuilder and returns the Message

§Examples

let message = MessageBuilder::new(
        ContactBuilder::new("from@example.com").build(),
        "Subject Line"
        )
        .build();

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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