sendgrid_rs/mail_settings.rs
1use serde::Serialize;
2
3/// Struct to store data and serialize to SendGrid's API for the mail_settings node
4/// Use MailSettingsBuilder to construct this
5#[derive(Serialize, Debug, Default)]
6pub struct MailSettings {
7 bcc: Option<BccSetting>,
8 bypass_list_management: Option<BypassListSetting>,
9 footer: Option<FooterSetting>,
10 sandbox_mode: Option<SandboxModeSetting>,
11 spam_check: Option<SpamCheckSetting>,
12}
13
14/// Builder pattern for creating `MailSettings` Make sure you call `build()` to consume this
15/// builder and get the underlying `MailSettings` Construct with default().
16#[derive(Default)]
17pub struct MailSettingsBuilder {
18 settings: MailSettings,
19}
20
21impl MailSettingsBuilder {
22 /// Adds the BCC setting to the `MailSettings` struct. It will always be enabled if this is
23 /// called. Just specify the email address to BCC.
24 ///
25 /// # Examples
26 /// ```
27 /// # use sendgrid_rs::MailSettingsBuilder;
28 ///
29 /// let builder = MailSettingsBuilder::default()
30 /// .bcc("bcc@example.com");
31 /// ```
32 pub fn bcc(mut self, email: impl Into<String>) -> Self {
33 self.settings.bcc = Some(BccSetting {
34 enable: true,
35 email: email.into(),
36 });
37 self
38 }
39
40 /// Turns on the flag for bypass_list_management in `MailSettings`.
41 ///
42 /// # Examples
43 /// ```
44 /// # use sendgrid_rs::MailSettingsBuilder;
45 ///
46 /// let builder = MailSettingsBuilder::default()
47 /// .bypass_list_management();
48 /// ```
49 pub fn bypass_list_management(mut self) -> Self {
50 self.settings.bypass_list_management = Some(BypassListSetting { enable: true });
51 self
52 }
53
54 /// Adds a footer to `MailSettings` text form is the optional first parameter, and html is the
55 /// second. Enabled flag is set to true when this method is called.
56 ///
57 /// # Examples
58 /// ```
59 /// # use sendgrid_rs::MailSettingsBuilder;
60 ///
61 /// let builder = MailSettingsBuilder::default()
62 /// .footer(Some(String::from("text footer")), Some(String::from("<h1>HTML Footer</h1>")));
63 /// ```
64 pub fn footer(mut self, text: Option<String>, html: Option<String>) -> Self {
65 self.settings.footer = Some(FooterSetting {
66 enable: true,
67 text,
68 html,
69 });
70 self
71 }
72
73 /// Enables the sandbox_mode flag for `MailSettings`
74 ///
75 /// # Examples
76 /// ```
77 /// # use sendgrid_rs::MailSettingsBuilder;
78 ///
79 /// let builder = MailSettingsBuilder::default()
80 /// .sandbox_mode();
81 /// ```
82 pub fn sandbox_mode(mut self) -> Self {
83 self.settings.sandbox_mode = Some(SandboxModeSetting { enable: true });
84 self
85 }
86
87 /// Configures the spam_check node for `MailSettings`
88 ///
89 /// # Parameters
90 /// threshold: Option<i32>
91 /// post_to_url: Option<String>
92 ///
93 /// # Examples
94 /// ```
95 /// # use sendgrid_rs::MailSettingsBuilder;
96 ///
97 /// let builder = MailSettingsBuilder::default()
98 /// .spam_check(Some(5), Some(String::from("http://post_url")));
99 /// ```
100 pub fn spam_check(mut self, threshold: Option<i32>, post_to_url: Option<String>) -> Self {
101 self.settings.spam_check = Some(SpamCheckSetting {
102 enable: true,
103 threshold,
104 post_to_url,
105 });
106 self
107 }
108
109 /// Consumes the `MailSettingsBuilder` and returns the underlying `MailSettings`
110 ///
111 /// # Examples
112 /// ```
113 /// # use sendgrid_rs::MailSettingsBuilder;
114 ///
115 /// let builder = MailSettingsBuilder::default()
116 /// .build();
117 /// ```
118 pub fn build(self) -> MailSettings {
119 self.settings
120 }
121}
122
123/// Struct used for serializing the Bcc node into SendGrid's API format. Use `MailSettingsBuilder`
124/// to configure this.
125#[derive(Serialize, Debug)]
126pub struct BccSetting {
127 enable: bool,
128 email: String,
129}
130
131/// Struct used for serializing the BypassList node into SendGrid's API format. Use
132/// `MailSettingsBuilder` to configure this.
133#[derive(Serialize, Debug)]
134pub struct BypassListSetting {
135 enable: bool,
136}
137
138/// Struct used for serializing the Footer node into SendGrid's API format. Use
139/// `MailSettingsBuilder` to configure this.
140#[derive(Serialize, Debug)]
141pub struct FooterSetting {
142 enable: bool,
143 text: Option<String>,
144 html: Option<String>,
145}
146
147/// Struct used for serializing the SandboxMode node into SendGrid's API format. Use
148/// `MailSettingsBuilder` to configure this.
149#[derive(Serialize, Debug)]
150pub struct SandboxModeSetting {
151 enable: bool,
152}
153
154/// Struct used for serializing the SpamCheck node into SendGrid's API format. Use
155/// `MailSettingsBuilder` to configure this.
156#[derive(Serialize, Debug)]
157pub struct SpamCheckSetting {
158 enable: bool,
159 threshold: Option<i32>,
160 post_to_url: Option<String>,
161}