Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new(credentials: Auth) -> Self

Examples found in repository?
examples/example.rs (line 13)
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}
Source

pub fn credentials(&self) -> &Auth

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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