![]() |
VOOZH | about |
dotnet add package Library.NET.Mailer --version 2025.3.19.1
NuGet\Install-Package Library.NET.Mailer -Version 2025.3.19.1
<PackageReference Include="Library.NET.Mailer" Version="2025.3.19.1" />
<PackageVersion Include="Library.NET.Mailer" Version="2025.3.19.1" />Directory.Packages.props
<PackageReference Include="Library.NET.Mailer" />Project file
paket add Library.NET.Mailer --version 2025.3.19.1
#r "nuget: Library.NET.Mailer, 2025.3.19.1"
#:package Library.NET.Mailer@2025.3.19.1
#addin nuget:?package=Library.NET.Mailer&version=2025.3.19.1Install as a Cake Addin
#tool nuget:?package=Library.NET.Mailer&version=2025.3.19.1Install as a Cake Tool
This is my personal wrapper for FluentEmail.Mailkit. It is designed to make my life easier interacting with my other programs.
IEmailerIEmailer emailer = new FluentEmailerMailKit();
EmailOptionsemailer.EmailOptions = new()
{
FromAddress = new("sender@test.com", "Tester"),
ToAddresses = new List<AddressModel>() { new("recipient@test.com"), new("recipient2@test.com") },
CcAddresses = new List<AddressModel>() { new("recipient3@test.com"), new("recipient4@test.com") },
BccAddresses = new List<AddressModel>() { new("recipient5@test.com"), new("recipient6@test.com") },
ReplyToAddress = new(),
Subject = "Test from Sender",
Body = "This is a test from the Tester program",
Attachments = new List<FileInfo>() { new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "New Text Document.txt")) },
Template = String.Empty,
IsBodyHTML = true
}
SmtpOptionsemailer.SmtpOptions = new()
{
Server = "mailserver.test.com",
Port = 25,
User = String.Empty,
Password = String.Empty,
UseSsl = false,
RequiresAuthentication = false,
PreferredEncoding = String.Empty,
UsePickupDirectory = false,
MailPickupDirectory = String.Empty,
SocketOptions = SecureSocketOptions.Auto
}
SendResponse result = await emailer.SetOptions().SendEmailAsync();
if (result.Successful)
{
Console.WriteLine("Success!");
}
else
{
StringBuilder stringBuilder = new();
foreach (var err in result.ErrorMessages)
{
stringBuilder.AppendLine(err);
}
Console.WriteLine(stringBuilder.ToString());
}
EmailOptions and SmtpOptions in .SetOptions()emailer.SetOptions(
new AddressModel("sender@test.com", "Tester"),
new List<AddressModel>() { new("recipient@test.com"), new("recipient2@test.com") },
new List<AddressModel>() { new("recipient3@test.com"), new("recipient4@test.com") },
new List<AddressModel>() { new("recipient5@test.com"), new("recipient6@test.com") },
new AddressModel(),
"Test from Sender",
"This is a test from the Tester program",
new List<FileInfo>() { new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "New Text Document.txt")) },
"",
true,
"mailserver.test.com",
25,
"",
"",
false,
false,
"",
false,
"",
SecureSocketOptions.Auto
)
.SendEmail();
EmailOptionsfromAddress: Sender informationreplyToAddress(optional): Address info for replies. Defaults to fromAddress.toAddresses, ccAddresses(optional), bccAddresses(optional): Recipient listssubject(optional): Subject line. Defaults to string.Empty.body(optional): The body of the email. Defaults to string.Empty.template(optional): Template for the email body. Defaults to string.Empty. (see example below)isBodyHtml(optional): Should the body be rendered as HTML?SmtpOptionsserver: SMTP server name or IP addressport(optional): TCP port the emailer uses to send the mail. Defaults to 25.user, password (both optional if requiresAuthentication is false): Credentials passed to the SMTP server for sending mail. Defaults to string.Empty.useSSL(optional): Does the server use SSL? Defaults to false.requiresAuthentication(optional): Does the server require authentication to send mail? Defaults to false.preferredEncoding(optional): Preferred encoding for the email. Defaults to string.Empty.usePickupDirectory(optional): Does the email use a pickup directory for delivery? Defaults to false.mailPickupDirectory(optional): Pickup directory for mail delivery. Defaults to string.Empty.socketOptions(optional): Provides a way of specifying the SSL and/or TLS encryption that should be used for a connection. Defaults to Auto, that is, If the server does not support SSL or TLS, then the connection will continue without any encryption.SendResponse result = await emailer.SetOptions().SendEmailAsync();
SendResponse result = emailer.SetOptions(
new AddressModel("sender@test.com", "Tester"),
new List<AddressModel>() { new("recipient@test.com"), new("recipient2@test.com") },
new List<AddressModel>() { new("recipient3@test.com"), new("recipient4@test.com") },
new List<AddressModel>() { new("recipient5@test.com"), new("recipient6@test.com") },
new AddressModel(),
"Test from Sender",
"This is a test from the Tester program",
new List<FileInfo>() { new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "New Text Document.txt")) },
"",
true,
"mailserver.test.com",
25,
"",
"",
false,
false,
"",
false,
"",
SecureSocketOptions.Auto
)
.SendEmail();
var template = new StringBuilder();
template.AppendLine("Dear @Model.FirstName,");
template.AppendLine("<p>Thanks for purchasing @Model.ProductName. We hope you enjoy it! </p>");
template.AppendLine("- COS Team");
emailer.EmailOptions.Template = template.ToString();
SendResponse result = emailer.SetOptions().SendEmailWithTemplate(new {FirstName = "John", ProductName = "Epic Razors"});
<PropertyGroup>
...
<PreserveCompilationContext>true</PreserveCompilationContext>
...
</PropertyGroup>
RazorRenderer(). That is why you have to put the <PreserveCompilationContext>true</PreserveCompilationContext> in the .csproj file.| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2025.3.19.1 | 334 | 3/20/2025 |
| 2023.11.18.1 | 371 | 11/18/2023 |
| 2022.4.7.2 | 660 | 4/7/2022 |
| 2022.4.7.1 | 641 | 4/7/2022 |