sendgrid_api/
send_test_email.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct SendTestEmail {
5    pub client: Client,
6}
7
8impl SendTestEmail {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        SendTestEmail { client }
12    }
13
14    /**
15     * Send a Test Marketing Email.
16     *
17     * This function performs a `POST` to the `/marketing/test/send_email` endpoint.
18     *
19     * **This endpoint allows you to send a test marketing email to a list of email addresses**.
20     *
21     * Before sending a marketing message, you can test it using this endpoint. You may specify up to **10 contacts** in the `emails` request body field. You must also specify a `template_id` and include either a `from_address` or `sender_id`. You can manage your templates with the [Twilio SendGrid App](https://mc.sendgrid.com/dynamic-templates) or the [Transactional Templates API](https://sendgrid.api-docs.io/v3.0/transactional-templates).
22     *
23     * > Please note that this endpoint works with Dynamic Transactional Templates only. Legacy Transactional Templates will not be delivered.
24     *
25     * For more information about managing Dynamic Transactional Templates, see [How to Send Email with Dynamic Transactional Templates](https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/).
26     *
27     * You can also test your Single Sends in the [Twilio SendGrid Marketing Campaigns UI](https://mc.sendgrid.com/single-sends).
28     */
29    pub async fn post_marketing_test_send_email(
30        &self,
31        body: &crate::types::PostMarketingTestSendEmailRequest,
32    ) -> ClientResult<crate::Response<crate::types::Help>> {
33        let url = self.client.url("/marketing/test/send_email", None);
34        self.client
35            .post(
36                &url,
37                crate::Message {
38                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
39                    content_type: Some("application/json".to_string()),
40                },
41            )
42            .await
43    }
44}