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