IDR.SendMail
3.2.1
See the version list below for details.
dotnet add package IDR.SendMail --version 3.2.1
NuGet\Install-Package IDR.SendMail -Version 3.2.1
<PackageReference Include="IDR.SendMail" Version="3.2.1" />
<PackageVersion Include="IDR.SendMail" Version="3.2.1" />
<PackageReference Include="IDR.SendMail" />
paket add IDR.SendMail --version 3.2.1
#r "nuget: IDR.SendMail, 3.2.1"
#:package IDR.SendMail@3.2.1
#addin nuget:?package=IDR.SendMail&version=3.2.1
#tool nuget:?package=IDR.SendMail&version=3.2.1
Copyright (c) 2024 Atsé Fabrice Igor KOMAN
This code is licensed under the MIT License.
/* =========================================================== FRANÇAIS =========================================================== */
Méthodes listées
Task SendMail(EmailModel emailModel);
Task<RenderedTemplate> RenderHtmlTemplateAsync(string templateName, Dictionary<string, string> values);
Comment utiliser :
Task SendMail(EmailModel emailModel);
Exemple 1 :
Dans Program.cs, ajoutez la ligne suivante
builder.Services.AddEmailServices((options) =>
{
options.FromMailId = "mail@example.com"; // Serveur mail pour l’envoi
options.FromMailIdPassword = "Password";
options.FromMailName = "DisplayName";
options.Host = "smtp.example.com";
options.Ports = 587;
options.IsBodyHtml = true;
options.EnableSsl = true;
options.LocalDomain = "example.com";
options.DirectoryTemplates = "EmailTemplates";
});
Dans le service d’e-mail :
using IDR.SendMail;
using IDR.SendMail.Interfaces;
public class SendMailServiceTest
{
private readonly ISendMailService _sendMailService;
public SendMailServiceTest(ISendMailService sendMailService)
{
_sendMailService = sendMailService;
}
public async void Mail()
{
var mail = new EmailModel
{
ToMailIds = new List<string>
{
"Mail1@example.com",
"Mail2@example.com"
},
Suject = "Objet",
Body = "Body"
};
await _sendMailService.SendMail(mail);
}
}
Exemple 2 :
Dans Program.cs, ajoutez la ligne suivante
builder.Services.AddEmailServices();
Dans le service d’e-mail :
using IDR.SendMail;
using IDR.SendMail.Interfaces;
public class SendMailServiceTest
{
private readonly ISendMailService _sendMailService;
public SendMailServiceTest(ISendMailService sendMailService)
{
_sendMailService = sendMailService;
}
public async void Mail()
{
var mail = new EmailModel
{
FromMailId = "mail@example.com", // Serveur mail pour l’envoi
FromMailIdPassword = "Password",
FromMailName = "DisplayName",
Host = "smtp.example.com",
Ports = 587,
ToMailIds = new List<string>
{
"Mail1@example.com",
"Mail2@example.com"
},
Suject = "Objet",
Body = "Body",
IsBodyHtml = true,
EnableSsl = true,
LocalDomain = "example.com"
// DirectoryTemplates ne fonctionne pas ici, vous devez le definir dans program.cs
};
await _sendMailService.SendMail(mail);
}
}
Exemple 3 : On peut combiner les exemples 1 et 2 selon ses besoins.
Comment utiliser :
Task<RenderedTemplate> RenderHtmlTemplateAsync(string templateName, Dictionary<string, string> values);
Créez un dossier Templates à la racine de votre projet et ajoutez votre fichier de template avec l’extension .html ou .cshtml.
Exemple : WelcomeTemplate.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mail Subject</title>
<style></style>
</head>
<body>
<h1>Bienvenue {{name}}</h1>
<p>Merci de nous avoir rejoint. Nous sommes ravis de vous compter parmi nous !</p>
<p>Votre adresse e-mail enregistrée est : {{email}}</p>
</body>
</html>
Dans le service d’e-mail :
var values = new Dictionary<string, string>
{
{ "name", $"{variableemail}" },
{ "email", $"{variableemail}" }
};
var mailContent = await _mailService.RenderHtmlTemplateAsync("WelcomeTemplate.html", values);
var mail = new EmailModel
{
ToMailIds = new List<string>()
{
user.Email
},
Suject = mailContent.Subject,
Body = mailContent.Body
};
await _mailService.SendMail(mail);
/* =========================================================== ENGLISH =========================================================== */
Listed Methods
Task SendMail(EmailModel emailModel);
Task<RenderedTemplate> RenderHtmlTemplateAsync(string templateName, Dictionary<string, string> values);
How to Use:
Task SendMail(EmailModel emailModel);
Example 1:
In Program.cs, add the following line
builder.Services.AddEmailServices((options) =>
{
options.FromMailId = "mail@example.com"; // Mail server for sending
options.FromMailIdPassword = "Password";
options.FromMailName = "DisplayName";
options.Host = "smtp.example.com";
options.Ports = 587;
options.IsBodyHtml = true;
options.EnableSsl = true;
options.LocalDomain = "example.com";
options.DirectoryTemplates = "EmailTemplates";
});
In the email service:
using IDR.SendMail;
using IDR.SendMail.Interfaces;
public class SendMailServiceTest
{
private readonly ISendMailService _sendMailService;
public SendMailServiceTest(ISendMailService sendMailService)
{
_sendMailService = sendMailService;
}
public async void Mail()
{
var mail = new EmailModel
{
ToMailIds = new List<string>
{
"Mail1@example.com",
"Mail2@example.com"
},
Suject = "Subject",
Body = "Body"
};
await _sendMailService.SendMail(mail);
}
}
Example 2:
In Program.cs, add the following line
builder.Services.AddEmailServices();
In the email service:
using IDR.SendMail;
using IDR.SendMail.Interfaces;
public class SendMailServiceTest
{
private readonly ISendMailService _sendMailService;
public SendMailServiceTest(ISendMailService sendMailService)
{
_sendMailService = sendMailService;
}
public async void Mail()
{
var mail = new EmailModel
{
FromMailId = "mail@example.com", // Mail server for sending
FromMailIdPassword = "Password",
FromMailName = "DisplayName",
Host = "smtp.example.com",
Ports = 25,
ToMailIds = new List<string>
{
"Mail1@example.com",
"Mail2@example.com"
},
Suject = "Subject",
Body = "Body",
IsBodyHtml = true,
EnableSsl = true,
LocalDomain = "example.com"
// DirectoryTemplates not working in this case, you have to define it in Program.cs
};
await _sendMailService.SendMail(mail);
}
}
Example 3: You can combine examples 1 and 2 as needed.
How to Use:
Task<RenderedTemplate> RenderHtmlTemplateAsync(string templateName, Dictionary<string, string> values);
Create a Templates folder at the root of your project and add your template file with the .html or .cshtml extension.
Example: WelcomeTemplate.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mail Subject</title>
<style></style>
</head>
<body>
<h1>Welcome {{name}}</h1>
<p>Thank you for joining us. We are excited to have you on board!</p>
<p>Your registered email is: {{email}}</p>
</body>
</html>
In the email service:
var values = new Dictionary<string, string>
{
{ "name", $"{variableemail}" },
{ "email", $"{variableemail}" }
};
var mailContent = await _mailService.RenderHtmlTemplateAsync("WelcomeTemplate.html", values);
var mail = new EmailModel
{
ToMailIds = new List<string>()
{
user.Email
},
Suject = mailContent.Subject,
Body = mailContent.Body
};
await _mailService.SendMail(mail);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- MailKit (>= 4.15.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.13)
- Microsoft.Extensions.Options (>= 9.0.13)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.3.2 | 133 | 3/8/2026 |
| 3.3.1 | 124 | 1/29/2026 |
| 3.3.0 | 143 | 1/21/2026 |
| 3.2.1 | 107 | 3/8/2026 |
| 3.2.0 | 198 | 1/15/2026 |
| 3.0.1 | 562 | 11/22/2025 |
| 3.0.0 | 513 | 11/22/2025 |
| 2.4.0 | 365 | 9/30/2025 |
| 2.2.2 | 328 | 9/18/2025 |
| 2.0.1 | 351 | 9/2/2024 |
| 2.0.0 | 145 | 9/2/2024 |
| 1.3.0 | 204 | 3/27/2024 |
| 1.2.0 | 174 | 3/26/2024 |
| 1.1.0 | 185 | 3/26/2024 |