azure_functions/send_grid/
mail_settings.rs

1use crate::send_grid::{BccSettings, BypassListManagement, FooterSettings, SandboxMode, SpamCheck};
2use serde::{Deserialize, Serialize};
3
4/// Represents a collection of different mail settings that specify how an email message is handled.
5#[derive(Debug, Default, Clone, Serialize, Deserialize)]
6pub struct MailSettings {
7    /// The BCC settings for the email message.
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub bcc: Option<BccSettings>,
10    /// The bypass list management settings for the email message.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub bypass_list_management: Option<BypassListManagement>,
13    /// The footer settings for the email message.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub footer: Option<FooterSettings>,
16    /// The sandbox mode settings for the email message.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub sandbox_mode: Option<SandboxMode>,
19    /// The spam check settings for the email message.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub spam_check: Option<SpamCheck>,
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use serde_json::to_string;
28
29    #[test]
30    fn it_serializes_to_json() {
31        let json = to_string(&MailSettings {
32            bcc: Some(BccSettings {
33                enable: true,
34                email: "foo@example.com".to_owned(),
35            }),
36            bypass_list_management: Some(BypassListManagement { enable: true }),
37            footer: Some(FooterSettings {
38                enable: true,
39                text: "hello".to_owned(),
40                html: "world".to_owned(),
41            }),
42            sandbox_mode: Some(SandboxMode { enable: true }),
43            spam_check: Some(SpamCheck {
44                enable: true,
45                threshold: 7,
46                post_to_url: "https://example.com".to_owned(),
47            }),
48        })
49        .unwrap();
50
51        assert_eq!(
52            json,
53            r#"{"bcc":{"enable":true,"email":"foo@example.com"},"bypass_list_management":{"enable":true},"footer":{"enable":true,"text":"hello","html":"world"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"threshold":7,"post_to_url":"https://example.com"}}"#
54        );
55    }
56}