Novely.Tools.Emails
2.0.0
dotnet add package Novely.Tools.Emails --version 2.0.0
NuGet\Install-Package Novely.Tools.Emails -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Novely.Tools.Emails" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Novely.Tools.Emails" Version="2.0.0" />
<PackageReference Include="Novely.Tools.Emails" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Novely.Tools.Emails --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Novely.Tools.Emails, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Novely.Tools.Emails@2.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Novely.Tools.Emails&version=2.0.0
#tool nuget:?package=Novely.Tools.Emails&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Novely.Tools.Emails
Service d'envoi d'e-mails via SMTP pour .NET 8.0, basé sur MailKit.
Installation
dotnet add package Novely.Tools.Emails
Configuration
Enregistrer le service via l'injection de dépendances :
builder.Services.AddEmailService(new EmailSettings
{
Server = "smtp.exemple.com",
Port = 465,
Sender = "noreply@exemple.com",
UseCredentials = true,
User = "utilisateur",
Password = "motdepasse"
});
Proprietes de EmailSettings
| Propriete | Type | Description |
|---|---|---|
Server |
string |
Adresse du serveur SMTP |
Port |
int |
Port du serveur SMTP |
Sender |
string |
Adresse e-mail de l'expediteur par defaut |
UseCredentials |
bool |
Active l'authentification SMTP (defaut : false) |
User |
string |
Nom d'utilisateur SMTP |
Password |
string |
Mot de passe SMTP |
RedirectEmails |
string |
Redirige tous les e-mails vers cette adresse (utile en dev) |
CciEmails |
string |
Adresses en copie cachee sur chaque envoi |
PickupDirectoryLocation |
string |
Si defini, les e-mails sont enregistres en fichier .eml au lieu d'etre envoyes |
Les adresses multiples sont separees par ;.
Utilisation
Injecter IEmailService puis appeler SendEmail :
public class MonService(IEmailService emailService)
{
public void EnvoyerNotification()
{
emailService.SendEmail(
subject: "Bienvenue",
body: "<h1>Bonjour</h1><p>Votre compte est actif.</p>",
recipient: "destinataire@exemple.com"
);
}
}
Envoyer avec des pieces jointes
var fichiers = new List<EmailFile>
{
new("rapport.pdf", pdfBytes),
new("image.png", imageBytes, new ContentType("image", "png"))
};
emailService.SendEmail(
subject: "Rapport mensuel",
body: "<p>Veuillez trouver le rapport en piece jointe.</p>",
recipient: "destinataire@exemple.com",
attachments: fichiers
);
Envoyer avec copie carbone (CC)
emailService.SendEmail(
recipient: "destinataire@exemple.com",
subject: "Mise a jour",
body: "<p>Information importante.</p>",
recipientCc: "copie@exemple.com"
);
Envoyer un MimeMessage personnalise
Pour un controle total, construire un MimeMessage et l'envoyer directement :
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Expediteur", "noreply@exemple.com"));
message.To.Add(new MailboxAddress("Destinataire", "contact@exemple.com"));
message.Subject = "Sujet personnalise";
message.Body = new TextPart("html") { Text = "<p>Contenu</p>" };
emailService.SendEmail(message);
Mode pickup directory
En definissant PickupDirectoryLocation, les e-mails sont sauvegardes en fichiers .eml dans le dossier indique au lieu d'etre envoyes via SMTP. Utile pour le developpement et les tests :
new EmailSettings
{
Sender = "noreply@exemple.com",
PickupDirectoryLocation = "/tmp/emails"
};
Licence
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- MailKit (>= 4.15.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- MimeKit (>= 4.15.1)
-
net8.0
- MailKit (>= 4.15.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- MimeKit (>= 4.15.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.