MailKitSimplified.Sender
1.1.1
See the version list below for details.
dotnet add package MailKitSimplified.Sender --version 1.1.1
NuGet\Install-Package MailKitSimplified.Sender -Version 1.1.1
<PackageReference Include="MailKitSimplified.Sender" Version="1.1.1" />
paket add MailKitSimplified.Sender --version 1.1.1
#r "nuget: MailKitSimplified.Sender, 1.1.1"
// Install MailKitSimplified.Sender as a Cake Addin #addin nuget:?package=MailKitSimplified.Sender&version=1.1.1 // Install MailKitSimplified.Sender as a Cake Tool #tool nuget:?package=MailKitSimplified.Sender&version=1.1.1
MailKitSimplified
Sending and receiving emails sounds simple, after all, electronic mail existed decades before the Internet. If you're looking for an all-in-one .NET solution for email, you'll quickly discover MailKit is recommended by even the likes of Microsoft due to how it implements the RFC standard. Unfortunately the downside of doing it all is that MailKit can be difficult to set up and use, especially the first time you go to try something like working with attachments or writing a reply. The aim of this package is to make sending and receiving emails as simple as possible!
Sending an email is now as easy as:
await smtpSender.WriteEmail.To("test@localhost").SendAsync();
Receiving emails is now as easy as:
var mimeMessages = await imapReceiver.ReadFrom("INBOX").GetMimeMessagesAsync();
MailKitSimplified.Sender Usage
Setup
If you're not familiar with dependency injection then you can specify the SMTP host address like this:
using var smtpSender = SmtpSender.Create("smtp.example.com");
An email sender must have a SMTP host address, and sometimes a port number, but leaving the port as the default value of 0 will normally choose the right port automatically (e.g. 25). Most companies use LDAP or something similar for behind-the-scenes authentication, but if not you can specify a network credential too.
Sending Mail
await smtpSender.WriteEmail
.From("my.name@example.com")
.To("YourName@example.com")
.Subject("Hello World")
.Attach(@"C:\Temp\EmailClientSmtp.log")
.SendAsync();
Using the method above will pass exceptions up to the next layer, but if you just want to log exceptions then continue with a "false" output that can also be done using the "try" prefix:
bool isSent = await smtpSender.WriteEmail
.From("me@example.com", "My Name")
.To("you@example.com", "Your Name")
.Cc("friend@example.com")
.Bcc("admin@localhost")
.Subject($"Hello at {DateTime.Now}!")
.BodyText("Optional text/plain content.")
.BodyHtml("Optional text/html content.<br/>")
.TryAttach("C:/Temp/attachment1.txt", "C:/Temp/attachment2.pdf")
.TrySendAsync();
_logger.LogInformation("Email {result}.", isSent ? "sent" : "failed to send");
Further examples (how to set up MailKit SMTP server logs etc.) can be found in the 'samples' and 'tests' folders on GitHub.
MailKitSimplified.Sender Dependency Injection
Dependency Injection is recommended over manual setup as the built-in garbage collector will handle lifetime and disposal.
using MailKitSimplified.Sender;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddHostedService<ExampleNamespace.Worker>();
services.AddMailKitSimplifiedEmailSender(context.Configuration);
})
.Build();
await host.RunAsync();
You'll also need the following in appsettings.json:
{
"EmailSender:SmtpHost": "smtp.example.com",
}
Other optional settings include SmtpPort, ProtocolLog, SmtpCredential:UserName and SmtpCredential:Password.
Now you can use the fully configured ISmtpSender or IEmailWriter anywhere you want with no other setup! For example:
public class EmailService
{
private readonly IEmailWriter _writeEmail;
public EmailService(IEmailWriter writeEmail) {
_writeEmail = writeEmail;
}
}
That's how sending an email can become as simple as one line of code.
await _writeEmail.To("test@localhost").SendAsync();
MailKitSimplified.Receiver Usage
Setup
If you're not familiar with dependency injection then you can specify the IMAP host address like this:
using var imapReceiver = ImapReceiver.Create("imap.example.com", 0, "U5ern@m3", "P455w0rd");
An email receiver must have a IMAP host address, a network credential (unless you're using something like smtp4dev), and sometimes a port number, but leaving the port as the default value of 0 will normally choose the right port automatically.
Receiving Mail
var mimeMessageQueue = await imapReceiver.ReadMail
.GetMimeMessagesAsync();
var mimeMessages = await imapReceiver.ReadFrom("INBOX/My Subfolder").Skip(0).Take(10)
.GetMessageSummariesAsync(MessageSummaryItems.UniqueId);
Further examples (how to set up MailKit IMAP server logs etc.) can be found in the 'samples' and 'tests' folders on GitHub.
MailKitSimplified.Receiver Dependency Injection
Dependency Injection is recommended over manual setup as the built-in garbage collector will handle lifetime and disposal.
using MailKitSimplified.Receiver;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddHostedService<ExampleNamespace.EmailService>();
services.AddMailKitSimplifiedEmailReceiver(context.Configuration);
})
.Build();
await host.RunAsync();
You'll also need the following in appsettings.json:
{
"EmailReceiver": {
"MailFolderName": "INBOX",
"ImapHost": "localhost",
"ImapPort": 143,
"ImapCredential": {
"UserName": "",
"Password": ""
},
"ProtocolLog": "Logs\\ImapClient.txt"
},
}
Now you can use the fully configured IImapReceiver or IMailReader anywhere you want with no other setup! For example:
public class EmailService
{
private readonly IMailReader _readEmail;
public EmailService(IMailReader readEmail) {
_readEmail = readEmail;
}
}
That's how receiving emails can become as simple as one line of code.
var mimeMessages = await _readEmail.Skip(0).Take(10).GetMimeMessagesAsync();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- MailKit (>= 3.4.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- MimeKit (>= 3.4.2)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.IO.Abstractions (>= 17.2.3)
-
net6.0
- MailKit (>= 3.4.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- MimeKit (>= 3.4.2)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.IO.Abstractions (>= 17.2.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MailKitSimplified.Sender:
Package | Downloads |
---|---|
MailKitSimplified.Email
Easy, fluent way to send, receive, forward, and reply to emails with MailKit. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.11.13 | 196 | 10/23/2024 |
2.11.12 | 568 | 8/25/2024 |
2.11.10 | 140 | 8/21/2024 |
2.11.9 | 271 | 8/7/2024 |
2.10.0 | 1,759 | 5/1/2024 |
2.9.0 | 2,897 | 12/15/2023 |
2.8.0 | 2,267 | 10/24/2023 |
2.7.0 | 702 | 9/28/2023 |
2.6.1 | 415 | 9/20/2023 |
2.6.0 | 344 | 9/20/2023 |
2.5.8 | 313 | 9/20/2023 |
2.5.7 | 340 | 9/19/2023 |
2.5.6 | 318 | 9/18/2023 |
2.5.5 | 433 | 9/14/2023 |
2.5.4 | 595 | 8/21/2023 |
2.5.3 | 378 | 8/19/2023 |
2.5.2 | 504 | 8/11/2023 |
2.5.1 | 498 | 7/30/2023 |
2.5.0 | 467 | 7/29/2023 |
2.4.7 | 1,250 | 1/25/2023 |
2.4.6 | 608 | 1/15/2023 |
2.4.5 | 582 | 1/15/2023 |
2.4.3 | 570 | 1/14/2023 |
2.4.2 | 607 | 1/10/2023 |
2.4.1 | 654 | 1/10/2023 |
2.4.0 | 673 | 12/12/2022 |
2.3.0 | 587 | 12/9/2022 |
2.2.0 | 607 | 12/6/2022 |
2.1.0 | 664 | 12/2/2022 |
2.0.0 | 635 | 12/1/2022 |
1.1.4 | 671 | 11/25/2022 |
1.1.3 | 615 | 11/24/2022 |
1.1.2 | 643 | 11/21/2022 |
1.1.1 | 649 | 11/17/2022 |
1.0.1 | 653 | 11/16/2022 |
0.2.1 | 696 | 11/12/2022 |
0.2.0 | 663 | 11/12/2022 |
0.1.3 | 669 | 11/11/2022 |
0.1.2.3 | 758 | 10/10/2022 |