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: StringContent-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
impl Attachment
Sourcepub fn builder() -> AttachmentBuilder
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
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'de> Deserialize<'de> for Attachment
impl<'de> Deserialize<'de> for Attachment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Attachment
impl RefUnwindSafe for Attachment
impl Send for Attachment
impl Sync for Attachment
impl Unpin for Attachment
impl UnwindSafe for Attachment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more