You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sending and receiving emails sounds simple, after all, electronic mail existed [decades](https://en.wikipedia.org/wiki/History_of_email) before the [Internet](https://en.wikipedia.org/wiki/History_of_the_Internet). If you're looking for a an all-in-one .NET solution for email, you'll quickly discover [MailKit](https://github.com/jstedfast/MailKit) is recommended by even the likes of [Microsoft](https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-6.0#remarks) due to how it implements the [RFC standard](https://www.rfc-editor.org/rfc/rfc2822). Unfortunately the downside of doing it all is that MailKit can be difficult to [set up](https://github.com/jstedfast/MailKit#using-mailkit) [and use](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#messages-1), especially the first time you go to try something like [checking attachments](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#q-how-do-i-tell-if-a-message-has-attachments) or [writing a reply](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#q-how-do-i-reply-to-a-message). The aim of this package is to make sending (and receiving) emails as simple as possible!
3
+
Sending and receiving emails sounds simple, after all, electronic mail existed [decades](https://en.wikipedia.org/wiki/History_of_email) before the [Internet](https://en.wikipedia.org/wiki/History_of_the_Internet). If you're looking for an all-in-one .NET solution for email, you'll quickly discover [MailKit](https://github.com/jstedfast/MailKit) is recommended by even the likes of [Microsoft](https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-6.0#remarks) due to how it implements the [RFC standard](https://www.rfc-editor.org/rfc/rfc2822). Unfortunately the downside of doing it all is that MailKit can be difficult to [set up](https://github.com/jstedfast/MailKit#using-mailkit) [and use](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#messages-1), especially the first time you go to try something like [checking attachments](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#q-how-do-i-tell-if-a-message-has-attachments) or [writing a reply](https://github.com/jstedfast/MimeKit/blob/master/FAQ.md#q-how-do-i-reply-to-a-message). The aim of this package is to make sending (and receiving) emails as simple as possible!
4
4
5
5
Sending an email is now as easy as:
6
6
```csharp
@@ -22,13 +22,12 @@ An email sender must have a SMTP host address, and sometimes a port number, but
22
22
### Sending Mail
23
23
24
24
```csharp
25
-
varemail=smtpSender.WriteEmail
26
-
.From("me@example.com")
27
-
.To("you@example.com")
28
-
.Subject("Hi")
29
-
.Body("~");
30
-
31
-
awaitemail.SendAsync();
25
+
awaitsmtpSender.WriteEmail
26
+
.From("my.name@example.com")
27
+
.To("YourName@example.com")
28
+
.Subject("Hello World")
29
+
.Attach(@"C:\Temp\EmailClientSmtp.log")
30
+
.SendAsync();
32
31
```
33
32
34
33
Any configuration issues will throw an exception, but you can also opt to just log any exceptions and continue with a `false` output:
@@ -37,22 +36,22 @@ Any configuration issues will throw an exception, but you can also opt to just l
_logger.LogInformation("Email {result}.", isSent?"sent":"failed to send");
49
48
```
50
49
51
-
Further examples (detailed MailKit SMPT server logs etc.) can be found in MailKitSimplifiedSenderUnitTests and the example solution file.
50
+
Further examples (how to set up MailKit SMTP server logs etc.) can be found in the 'samples' and 'tests' folders on [GitHub](https://github.com/danzuep/MailKitSimplified).
52
51
53
52
### Dependency Injection
54
53
55
-
This is recommended over manual setup as the built-in garbage collector will handle lifetime and disposal.
54
+
[Dependency Injection](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-usage#register-services-for-di) is recommended over manual setup as the built-in garbage collector will handle lifetime and disposal.
56
55
57
56
```csharp
58
57
usingMailKitSimplified.Sender.Extensions;
@@ -78,15 +77,15 @@ You'll also need the following in appsettings.json:
78
77
79
78
Other optional settings include SmtpPort, ProtocolLog, SmtpCredential:UserName and SmtpCredential:Password.
80
79
81
-
Now you can use the fully configured IEmailSender or IEmailWriter anywhere you want with no other setup! For example:
80
+
Now you can use the fully configured ISmtpSender or IEmailWriter anywhere you want with no other setup! For example:
@@ -111,6 +110,8 @@ An email receiver must have a IMAP host address, a network credential (unless yo
111
110
112
111
### Receiving Mail
113
112
113
+
This hasn't been published yet, but here's what I'm building at the moment:
114
+
114
115
```csharp
115
116
varmailboxReceiver=imapReceiver
116
117
.ReadFrom("INBOX")
@@ -126,4 +127,4 @@ var mimeMessageQueue = await imapReceiver
126
127
.GetMimeMessagesAsync();
127
128
```
128
129
129
-
Further examples (detailed MailKit IMAP server logs etc.) can be found in the 'samples' and 'tests' folders.
130
+
Further examples (how to set up MailKit IMAP server logs etc.) can be found in the 'samples' and 'tests' folders on [GitHub](https://github.com/danzuep/MailKitSimplified).
0 commit comments