Skip to main content

Attachment

Struct Attachment 

Source
pub struct Attachment {
    pub content: Option<Base64>,
    pub content_id: Option<String>,
    pub content_type: Option<String>,
    pub disposition: String,
    pub filename: Option<String>,
}
Expand description

Email attachment.

Fields§

§content: Option<Base64>§content_id: Option<String>

Content-ID header (required for disposition related). Example: part1.DE1D8F7E.E51807FF@flowmailer.com.

§content_type: Option<String>

Examples: application/pdf, image/jpeg.

§disposition: String

Content-Disposition header for the attachment. Supported values include: attachment, inline and related. Special value related should be used for images referenced in the HTML.

§filename: Option<String>

Implementations§

Source§

impl Attachment

Source

pub fn builder() -> AttachmentBuilder

Creates a new AttachmentBuilder.

Examples found in repository?
examples/example.rs (line 31)
4async fn main() {
5    static CLIENT_ID: &str = "[ID]";
6    static CLIENT_SECRET: &str = "[SECRET]";
7    static ACCOUNT_ID: &str = "[ACCOUNT ID]";
8    let auth = auth::Auth::new(
9        auth::ClientSecret::new(CLIENT_SECRET.to_string()),
10        auth::ClientId::new(CLIENT_ID.to_string()),
11        auth::AccountId::new(ACCOUNT_ID.to_string()),
12    );
13    let flowmailer = Client::new(auth);
14
15    // Example 1: Template email with attachment
16    let pdf_bytes: Vec<u8> = vec![/* PDF file bytes would go here */];
17    let mailbuilder = MailBuilder::new_template(
18        MailAddress::new("sender@example.com"),
19        MailAddress::new("receiver@example.com"),
20        "[FLOW SELECTOR]",
21    )
22    // Set variables within the template.
23    .set_data(serde_json::json!({
24        "code": "123456"
25    }))
26    .expect("set data")
27    // Set the subject of the mail.
28    .set_subject("test_flowmailer_template_mail")
29    // Add an attachment
30    .add_attachment(
31        Attachment::builder()
32            .filename("report.pdf")
33            .content_type("application/pdf")
34            .content_bytes(&pdf_bytes)
35            .build(),
36    );
37    // Sends the mail.
38    mailbuilder.send(&flowmailer).await.expect("failed to send");
39
40    // Example 2: Plain text email with multiple attachments
41    let image_bytes: Vec<u8> = vec![/* Image bytes would go here */];
42    let text_mail = MailBuilder::new_text(
43        MailAddress::new("sender@example.com"),
44        MailAddress::new("receiver@example.com"),
45        "Hello! Please find the attached files.",
46    )
47    .set_subject("Files attached")
48    .add_attachment(
49        Attachment::builder()
50            .filename("document.pdf")
51            .content_type("application/pdf")
52            .content_bytes(&pdf_bytes)
53            .build(),
54    )
55    .add_attachment(
56        Attachment::builder()
57            .filename("photo.jpg")
58            .content_type("image/jpeg")
59            .content_bytes(&image_bytes)
60            .build(),
61    );
62    text_mail.send(&flowmailer).await.expect("failed to send");
63
64    // Example 3: HTML email with inline image
65    let html_mail = MailBuilder::new_hmtl(
66        MailAddress::new("sender@example.com"),
67        MailAddress::new("receiver@example.com"),
68        r#"<html><body><h1>Hello!</h1><img src="cid:logo123"/></body></html>"#,
69    )
70    .set_subject("HTML with inline image")
71    .add_attachment(
72        Attachment::builder()
73            .filename("logo.png")
74            .content_type("image/png")
75            .content_bytes(&image_bytes)
76            .content_id("<logo123>")
77            .disposition_related() // Use "related" for inline images
78            .build(),
79    );
80    html_mail.send(&flowmailer).await.expect("failed to send");
81}

Trait Implementations§

Source§

impl Clone for Attachment

Source§

fn clone(&self) -> Attachment

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<'de> Deserialize<'de> for Attachment

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 Attachment

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§

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