@@ -13,18 +13,9 @@ pub struct Mail {
13
13
/// The email address to reply to.
14
14
#[ serde( default = "Mail::default_reply_to" ) ]
15
15
pub reply_to : Mailbox ,
16
- /// The username to use for SMTP authentication.
17
- #[ serde( default = "Mail::default_username" ) ]
18
- pub username : String ,
19
- /// The password to use for SMTP authentication.
20
- #[ serde( default = "Mail::default_password" ) ]
21
- pub password : String ,
22
- /// The SMTP server to use.
23
- #[ serde( default = "Mail::default_server" ) ]
24
- pub server : String ,
25
- /// The SMTP port to use.
26
- #[ serde( default = "Mail::default_port" ) ]
27
- pub port : u16 ,
16
+ /// The SMTP server configuration.
17
+ #[ serde( default = "Mail::default_smtp" ) ]
18
+ pub smtp : Smtp ,
28
19
}
29
20
30
21
impl Default for Mail {
@@ -33,10 +24,7 @@ impl Default for Mail {
33
24
email_verification_enabled : Self :: default_email_verification_enabled ( ) ,
34
25
from : Self :: default_from ( ) ,
35
26
reply_to : Self :: default_reply_to ( ) ,
36
- username : Self :: default_username ( ) ,
37
- password : Self :: default_password ( ) ,
38
- server : Self :: default_server ( ) ,
39
- port : Self :: default_port ( ) ,
27
+ smtp : Self :: default_smtp ( ) ,
40
28
}
41
29
}
42
30
}
@@ -54,19 +42,75 @@ impl Mail {
54
42
"noreply@email.com" . parse ( ) . expect ( "valid mailbox" )
55
43
}
56
44
57
- fn default_username ( ) -> String {
58
- String :: default ( )
45
+ fn default_smtp ( ) -> Smtp {
46
+ Smtp :: default ( )
59
47
}
48
+ }
60
49
61
- fn default_password ( ) -> String {
62
- String :: default ( )
50
+ /// SMTP configuration.
51
+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
52
+ pub struct Smtp {
53
+ /// The SMTP port to use.
54
+ #[ serde( default = "Smtp::default_port" ) ]
55
+ pub port : u16 ,
56
+ /// The SMTP server to use.
57
+ #[ serde( default = "Smtp::default_server" ) ]
58
+ pub server : String ,
59
+ /// The SMTP server credentials.
60
+ #[ serde( default = "Smtp::default_credentials" ) ]
61
+ pub credentials : Credentials ,
62
+ }
63
+
64
+ impl Default for Smtp {
65
+ fn default ( ) -> Self {
66
+ Self {
67
+ server : Self :: default_server ( ) ,
68
+ port : Self :: default_port ( ) ,
69
+ credentials : Self :: default_credentials ( ) ,
70
+ }
63
71
}
72
+ }
64
73
74
+ impl Smtp {
65
75
fn default_server ( ) -> String {
66
76
String :: default ( )
67
77
}
68
78
69
79
fn default_port ( ) -> u16 {
70
80
25
71
81
}
82
+
83
+ fn default_credentials ( ) -> Credentials {
84
+ Credentials :: default ( )
85
+ }
86
+ }
87
+
88
+ /// SMTP configuration.
89
+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
90
+ pub struct Credentials {
91
+ /// The password to use for SMTP authentication.
92
+ #[ serde( default = "Credentials::default_password" ) ]
93
+ pub password : String ,
94
+ /// The username to use for SMTP authentication.
95
+ #[ serde( default = "Credentials::default_username" ) ]
96
+ pub username : String ,
97
+ }
98
+
99
+ impl Default for Credentials {
100
+ fn default ( ) -> Self {
101
+ Self {
102
+ username : Self :: default_username ( ) ,
103
+ password : Self :: default_password ( ) ,
104
+ }
105
+ }
106
+ }
107
+
108
+ impl Credentials {
109
+ fn default_username ( ) -> String {
110
+ String :: default ( )
111
+ }
112
+
113
+ fn default_password ( ) -> String {
114
+ String :: default ( )
115
+ }
72
116
}
0 commit comments