postmark_client/
emails.rs

1use serde::Serialize;
2
3use crate::{
4    types::{Email, EmailResponse, TemplatedEmail},
5    Client, Result,
6};
7
8impl Client {
9    /// Sends a batch of Emails in a single request, each email in the batch has a corresponding
10    /// EmailResponse in the result of this function.
11    ///
12    /// <https://postmarkapp.com/developer/api/email-api#send-batch-emails>
13    pub async fn send_batch_emails(&self, emails: &[Email]) -> Result<Vec<EmailResponse>> {
14        self.post("/email/batch", emails).await
15    }
16    /// Sends a batch of template emails in a single request, each email in the batch has a
17    /// corresponding EmailResoinse in the result of this function.
18    ///
19    /// <https://postmarkapp.com/developer/api/templates-api#send-batch-with-templates>
20    pub async fn send_batch_template_emails<M>(
21        &self,
22        email: &[TemplatedEmail<M>],
23    ) -> Result<EmailResponse>
24    where
25        M: Serialize,
26    {
27        //TODO: Fix this function to support emails with different types of models
28        self.post("/email/batchWithTemplates", email).await
29    }
30    /// Sends an email.
31    ///
32    /// <https://postmarkapp.com/developer/api/email-api#send-a-single-email>
33    pub async fn send_email(&self, email: &Email) -> Result<EmailResponse> {
34        self.post("/email", email).await
35    }
36    /// Sends a template email.
37    ///
38    /// <https://postmarkapp.com/developer/api/templates-api#email-with-template>
39    pub async fn send_template_email<M>(&self, email: &TemplatedEmail<M>) -> Result<EmailResponse>
40    where
41        M: Serialize,
42    {
43        self.post("/email/withTemplate", email).await
44    }
45}