1
1
## Email Service Configuration
2
2
3
3
The MailService provides email functionality using SMTP protocol. It supports:
4
+
4
5
- Account activation emails
5
6
- Password reset emails
6
7
- Welcome emails
@@ -31,12 +32,16 @@ Configure email settings in `appsettings.json`:
31
32
```
32
33
33
34
#### Development Configuration
35
+
34
36
For local development, you can use:
37
+
35
38
- [ MailHog] ( https://github.com/mailhog/MailHog ) - Recommended for Mac/Linux
36
39
- [ Papercut SMTP] ( https://github.com/ChangemakerStudios/Papercut-SMTP ) - Windows alternative
37
40
38
41
#### Production Configuration
42
+
39
43
Common SMTP providers:
44
+
40
45
- Gmail SMTP:
41
46
``` json
42
47
"Smtp" : {
@@ -57,6 +62,7 @@ Common SMTP providers:
57
62
### Usage Examples
58
63
59
64
1 . Activation Email:
65
+
60
66
``` csharp
61
67
await _mailService .SendActivationEmail (
62
68
@@ -66,6 +72,7 @@ await _mailService.SendActivationEmail(
66
72
```
67
73
68
74
2 . Password Reset:
75
+
69
76
``` csharp
70
77
await _mailService .SendPasswordResetMail (
71
78
@@ -75,6 +82,7 @@ await _mailService.SendPasswordResetMail(
75
82
```
76
83
77
84
3 . Welcome Email:
85
+
78
86
``` csharp
79
87
await _mailService .SendCreationEmail (
80
88
@@ -85,6 +93,7 @@ await _mailService.SendCreationEmail(
85
93
### Security Best Practices
86
94
87
95
1 . ** SMTP Security**
96
+
88
97
- Enable TLS/SSL encryption (` UseSsl: true ` )
89
98
- Use environment variables for credentials:
90
99
``` json
@@ -95,6 +104,7 @@ await _mailService.SendCreationEmail(
95
104
- Use dedicated sending domains
96
105
97
106
2 . **Content Security**
107
+
98
108
- Sanitize all user input in templates
99
109
- Include SPF/DKIM records for your domain
100
110
- Set up DMARC policy
@@ -108,16 +118,17 @@ await _mailService.SendCreationEmail(
108
118
### Testing
109
119
110
120
1 . Unit Testing:
121
+
111
122
```csharp
112
123
[Fact ]
113
124
public async Task Should_Send_Activation_Email()
114
125
{
115
126
// Arrange
116
127
var mockMailService = new Mock<IMailService>();
117
-
128
+
118
129
// Act
119
130
await mailService.SendActivationEmail("[email protected] ", "Test User", "key123");
120
-
131
+
121
132
// Assert
122
133
mockMailService.Verify(x => x.SendActivationEmail(
123
134
It.IsAny<string>(),
@@ -128,12 +139,13 @@ public async Task Should_Send_Activation_Email()
128
139
```
129
140
130
141
2 . Integration Testing:
142
+
131
143
``` csharp
132
144
[Fact ]
133
145
public async Task Should_Connect_To_SMTP_Server ()
134
146
{
135
147
// Use MailHog for integration tests
136
- var mailConfig = new MailConfiguration
148
+ var mailConfig = new MailConfiguration
137
149
{
138
150
Host = " localhost" ,
139
151
Port = 1025
@@ -147,8 +159,8 @@ public async Task Should_Connect_To_SMTP_Server()
147
159
- Verify network connectivity to SMTP server
148
160
- Check firewall rules for SMTP ports (25, 465, 587)
149
161
- Validate SSL certificate if using TLS
150
-
151
162
2 . ** Authentication Problems**
163
+
152
164
- Ensure credentials are correctly encoded
153
165
- Check for IP-based restrictions
154
166
- Verify OAuth2 settings if applicable
@@ -173,4 +185,4 @@ public async Task Should_Connect_To_SMTP_Server()
173
185
174
186
- [ JHipster Email Configuration Guide] ( https://www.jhipster.tech/tips/011_tip_configuring_email_in_jhipster.html )
175
187
- [ MailKit Documentation] ( https://github.com/jstedfast/MailKit#documentation )
176
- - [ SMTP Security Best Practices] ( https://www.m3aawg.org/published-documents )
188
+ - [ SMTP Security Best Practices] ( https://www.m3aawg.org/published-documents )
0 commit comments