Skip to content

Commit f78d97c

Browse files
committed
chore: Update Mail Service documentation and fix MySQL provider typo
1 parent 6912f30 commit f78d97c

File tree

3 files changed

+90
-54
lines changed

3 files changed

+90
-54
lines changed

content/en/dotnet-templates/fundamentals/mail-service.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,90 @@ weight: 11
1515
toc: true
1616
---
1717

18-
Documentation Coming Soon!
18+
Mail Service in Genocs Library's Web API is a service that allows you to send emails from your application.
19+
20+
There are two ways to send emails using the Mail Service:
21+
- By using [Sendgrid](https://sendgrid.com/)
22+
- By using SMTP with [MailKit](https://mimekit.net/)
23+
24+
25+
## Sendgrid
26+
27+
Sendgrid is a cloud-based email service that provides reliable transactional email delivery. It is a popular choice for sending emails from your application. To use Sendgrid with the Mail Service, you need to configure the Sendgrid API key in the `appsettings.json` file.
28+
29+
### Configure Sendgrid API Key
30+
31+
1. Sign up for a [Sendgrid account](https://sendgrid.com/).
32+
2. Create a new API key in the Sendgrid dashboard.
33+
3. Add the Sendgrid API key to the `appsettings.json` file.
34+
35+
```json
36+
{
37+
"Sendgrid": {
38+
"ApiKey": "YOUR_SENDGRID_API_KEY"
39+
}
40+
}
41+
```
42+
43+
### Send Email using Sendgrid
44+
45+
To send an email using Sendgrid, you need to create an instance of the `SendgridMailService` class and call the `SendEmailAsync` method.
46+
47+
48+
This code snippet is used to send an email using SendGrid. The code snippet is written in C# and uses the SendGrid NuGet package. The code snippet is used to send an email to multiple recipients. The code snippet is written in C# and uses the SendGrid NuGet package. The code snippet is used to send an email to multiple recipients.
49+
50+
```csharp
51+
52+
/// <summary>
53+
/// Send Email using Sendgrid
54+
/// </summary>
55+
/// <param name="subject">Email Subject</param>
56+
/// <param name="content">Email Content</param>
57+
private async Task InternalSend(string subject, string content)
58+
{
59+
try
60+
{
61+
var client = new SendGridClient(_settings.ApiKey);
62+
var from = new EmailAddress(_settings.Email);
63+
var plainTextContent = "This email is generated by the system. Please do not respond on this account";
64+
65+
var recipients = _settings.Recipients.Split(",");
66+
if (recipients.Length == 1)
67+
{
68+
var to = new EmailAddress(_settings.Recipients);
69+
var msg = MailHelper.CreateSingleEmail(from,
70+
to,
71+
subject,
72+
plainTextContent,
73+
content);
74+
var response = await client.SendEmailAsync(msg);
75+
var res = response.IsSuccessStatusCode;
76+
}
77+
else
78+
{
79+
var recipientsAddress = new List<EmailAddress>();
80+
foreach (string recipient in recipients)
81+
{
82+
if (!string.IsNullOrWhiteSpace(recipient))
83+
{
84+
recipientsAddress.Add(new EmailAddress(recipient.Trim()));
85+
}
86+
}
87+
88+
var to = new EmailAddress(_settings.Recipients);
89+
var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from,
90+
recipientsAddress,
91+
subject,
92+
plainTextContent,
93+
content);
94+
95+
var response = await client.SendEmailAsync(msg);
96+
var res = response.IsSuccessStatusCode;
97+
}
98+
}
99+
catch (System.Exception ex)
100+
{
101+
_logger.LogError("Error on Send Email", ex);
102+
}
103+
}
104+
```

content/en/dotnet-templates/tutorials/database-migrations/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Below are some sample configurations for MySQL Provider. The above is applicable
203203
204204
The Provider values for other supported DBs are as follows.
205205
- MSSQL - **mssql**
206-
- MYSQL - **mssql**
206+
- MYSQL - **mysql**
207207
- Oracle - **oracle**
208208
- PostgreSQL - **postgresql**
209209
- SQLite - **sqlite**
@@ -212,6 +212,8 @@ Once your connection strings are all updated in the mentioned configuration file
212212

213213
As mentioned earlier, since we have 2 Db Contexts defined in our application, we will have seperate commands for each of the available context classes.
214214

215+
**Move to the WebAPI project directory and run the following commands.**
216+
215217
The generic command to add migrations over the **Application Db Context** goes like this:
216218

217219
``` bash

content/en/library/messaging/index.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,3 @@ toc: true
1616
---
1717

1818

19-
This code snippet is used to send an email using SendGrid. The code snippet is written in C# and uses the SendGrid NuGet package. The code snippet is used to send an email to multiple recipients. The code snippet is written in C# and uses the SendGrid NuGet package. The code snippet is used to send an email to multiple recipients.
20-
21-
```csharp
22-
23-
private async Task InternalSend(string subject, string content)
24-
{
25-
try
26-
{
27-
var client = new SendGridClient(_settings.ApiKey);
28-
var from = new EmailAddress(_settings.Email);
29-
var plainTextContent = "This email is generated by the system. Please do not respond on this account";
30-
31-
var recipients = _settings.Recipients.Split(",");
32-
if (recipients.Length == 1)
33-
{
34-
var to = new EmailAddress(_settings.Recipients);
35-
var msg = MailHelper.CreateSingleEmail(from,
36-
to,
37-
subject,
38-
plainTextContent,
39-
content);
40-
var response = await client.SendEmailAsync(msg);
41-
var res = response.IsSuccessStatusCode;
42-
}
43-
else
44-
{
45-
var recipientsAddress = new List<EmailAddress>();
46-
foreach (string recipient in recipients)
47-
{
48-
if (!string.IsNullOrWhiteSpace(recipient))
49-
{
50-
recipientsAddress.Add(new EmailAddress(recipient.Trim()));
51-
}
52-
}
53-
54-
var to = new EmailAddress(_settings.Recipients);
55-
var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from,
56-
recipientsAddress,
57-
subject,
58-
plainTextContent,
59-
content);
60-
61-
var response = await client.SendEmailAsync(msg);
62-
var res = response.IsSuccessStatusCode;
63-
}
64-
}
65-
catch (System.Exception ex)
66-
{
67-
_logger.LogError("Error on Send Email", ex);
68-
}
69-
}
70-
```

0 commit comments

Comments
 (0)