spring_mail/
config.rs

1use schemars::JsonSchema;
2use serde::Deserialize;
3use spring::config::Configurable;
4
5spring::submit_config_schema!("mail", MailerConfig);
6
7/// SMTP mailer configuration structure.
8#[derive(Debug, Configurable, Clone, JsonSchema, Deserialize)]
9#[config_prefix = "mail"]
10pub struct MailerConfig {
11    /// Mailer transport
12    #[serde(flatten)]
13    pub transport: Option<SmtpTransportConfig>,
14    /// Creates a `AsyncSmtpTransportBuilder` from a [connection URL](https://docs.rs/lettre/latest/lettre/transport/smtp/struct.AsyncSmtpTransport.html#method.from_url)
15    pub uri: Option<String>,
16    /// Tests the SMTP connection
17    #[serde(default = "bool::default")]
18    pub test_connection: bool,
19    /// Use stub transport. This transport logs messages and always returns the given response.
20    /// It can be useful for testing purposes.
21    #[serde(default = "bool::default")]
22    pub stub: bool,
23}
24
25#[derive(Debug, Clone, JsonSchema, Deserialize)]
26pub struct SmtpTransportConfig {
27    /// SMTP host. for example: localhost, smtp.gmail.com etc.
28    pub host: String,
29    /// SMTP port
30    pub port: u16,
31    /// Enable TLS
32    #[serde(default = "bool::default")]
33    pub secure: bool,
34    /// Auth SMTP server
35    pub auth: Option<MailerAuth>,
36}
37
38/// Authentication details for the mailer
39#[derive(Debug, Clone, JsonSchema, Deserialize)]
40pub struct MailerAuth {
41    /// User
42    pub user: String,
43    /// Password
44    pub password: String,
45}