@@ -99,6 +99,8 @@ pub struct Config {
9999 pub orion_server : Option < OrionServerConfig > ,
100100 #[ serde( default ) ]
101101 pub sidebar : SidebarConfig ,
102+ #[ serde( default ) ]
103+ pub mail : Option < MailConfig > ,
102104}
103105
104106impl Config {
@@ -137,6 +139,7 @@ impl Config {
137139 object_storage : ObjectStorageConfig :: default ( ) ,
138140 orion_server : None ,
139141 sidebar : SidebarConfig :: default ( ) ,
142+ mail : None ,
140143 }
141144 }
142145
@@ -266,6 +269,29 @@ impl Default for LogConfig {
266269 }
267270}
268271
272+ #[ derive( Deserialize , Debug , Clone ) ]
273+ pub struct MailConfig {
274+ #[ serde( default ) ]
275+ pub enabled : bool ,
276+ pub smtp_host : String ,
277+ #[ serde( default = "default_smtp_port" ) ]
278+ pub smtp_port : u16 ,
279+ #[ serde( default ) ]
280+ pub username : Option < String > ,
281+ #[ serde( default ) ]
282+ pub password : Option < String > ,
283+ pub from : String ,
284+ #[ serde( default = "default_starttls" ) ]
285+ pub starttls : bool ,
286+ }
287+
288+ fn default_smtp_port ( ) -> u16 {
289+ 587
290+ }
291+ fn default_starttls ( ) -> bool {
292+ true
293+ }
294+
269295#[ derive( Serialize , Deserialize , Debug , Clone ) ]
270296pub struct DbConfig {
271297 pub db_type : String ,
@@ -1069,4 +1095,29 @@ mod test {
10691095 } ;
10701096 assert ! ( config. validate( ) . is_ok( ) ) ;
10711097 }
1098+
1099+ #[ test]
1100+ fn test_mail_config_deserialize ( ) {
1101+ use serde:: Deserialize ;
1102+ #[ derive( Deserialize ) ]
1103+ struct Wrapper {
1104+ mail : MailConfig ,
1105+ }
1106+
1107+ let toml = r#"
1108+ [mail]
1109+ enabled = true
1110+ smtp_host = "smtp.example.com"
1111+ smtp_port = 587
1112+ from = "no-reply@example.com"
1113+ starttls = true
1114+ "# ;
1115+
1116+ let parsed: Wrapper = toml:: from_str ( toml) . expect ( "MailConfig should deserialize" ) ;
1117+ assert ! ( parsed. mail. enabled) ;
1118+ assert_eq ! ( parsed. mail. smtp_host, "smtp.example.com" ) ;
1119+ assert_eq ! ( parsed. mail. smtp_port, 587 ) ;
1120+ assert_eq ! ( parsed. mail. from, "no-reply@example.com" ) ;
1121+ assert ! ( parsed. mail. starttls) ;
1122+ }
10721123}
0 commit comments