spring_mail/
config.rs

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