Skip to main content

rok_mail/
config.rs

1#[derive(Debug, Clone)]
2pub struct MailConfig {
3    /// Driver to use: "log" (default, prints to stdout) or "smtp".
4    pub driver: String,
5    /// Envelope from address.
6    pub from_address: String,
7    /// Display name for the from address.
8    pub from_name: String,
9    /// Default reply-to address.
10    pub reply_to: Option<String>,
11    /// SMTP host (required when driver = "smtp").
12    pub smtp_host: Option<String>,
13    /// SMTP port. Default: 587.
14    pub smtp_port: u16,
15    /// SMTP username for authentication.
16    pub smtp_username: Option<String>,
17    /// SMTP password for authentication.
18    pub smtp_password: Option<String>,
19    /// Encryption mode: "starttls" (default), "tls", or "none".
20    pub smtp_encryption: String,
21    /// API key for the Postmark driver.
22    pub postmark_api_key: Option<String>,
23    /// API key for the Resend driver.
24    pub resend_api_key: Option<String>,
25}
26
27impl MailConfig {
28    /// Set the default from address and display name (builder style).
29    pub fn from(mut self, address: impl Into<String>, name: impl Into<String>) -> Self {
30        self.from_address = address.into();
31        self.from_name = name.into();
32        self
33    }
34
35    /// Set the default reply-to address.
36    pub fn reply_to(mut self, address: impl Into<String>) -> Self {
37        self.reply_to = Some(address.into());
38        self
39    }
40
41    /// Set the SMTP host (builder style).
42    pub fn smtp_host(mut self, host: impl Into<String>) -> Self {
43        self.smtp_host = Some(host.into());
44        self
45    }
46
47    /// Set the SMTP port (builder style).
48    pub fn smtp_port(mut self, port: u16) -> Self {
49        self.smtp_port = port;
50        self
51    }
52
53    /// Set the Postmark API key (builder style).
54    pub fn postmark_key(mut self, key: impl Into<String>) -> Self {
55        self.postmark_api_key = Some(key.into());
56        self
57    }
58
59    /// Set the Resend API key (builder style).
60    pub fn resend_key(mut self, key: impl Into<String>) -> Self {
61        self.resend_api_key = Some(key.into());
62        self
63    }
64}
65
66impl Default for MailConfig {
67    fn default() -> Self {
68        Self {
69            driver: "log".into(),
70            from_address: "noreply@rok-app.com".into(),
71            from_name: "rok-app".into(),
72            reply_to: None,
73            smtp_host: None,
74            smtp_port: 587,
75            smtp_username: None,
76            smtp_password: None,
77            smtp_encryption: "starttls".into(),
78            postmark_api_key: None,
79            resend_api_key: None,
80        }
81    }
82}