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
# MailKitSimplified [](https://github.com/danzuep/MailKitSimplified/actions/workflows/development.yml)
2
2
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 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). Unfortunately for new users though, MailKit can do too much, so when I first started using it I was surprised at how many configuration steps were involved in getting it set up, and on the receiving end how poorly some real-world SMTP servers out there implement [the standard](https://www.rfc-editor.org/rfc/rfc2822). The aim of this package is to make sending an email 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 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!
4
4
5
-
## Sender Usage
5
+
Sending an email is now as easy as:
6
+
```csharp
7
+
awaitwriteEmail.To("test@localhost").SendAsync();
8
+
```
9
+
10
+
## MailKitSimplified.Sender Usage
6
11
7
12
### Setup
8
13
9
-
If you're not familiar with dependency injection then just use this:
10
-
```
11
-
using var smtpSender = MimeMessageSender.Create("smtp.example.com");
14
+
If you're not familiar with dependency injection then you can specify the SMTP host address like this:
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.
21
+
14
22
### Sending Mail
15
23
16
-
```
24
+
```csharp
17
25
varemail=smtpSender.WriteEmail
18
26
.From("me@example.com")
19
27
.To("you@example.com")
@@ -23,17 +31,16 @@ var email = smtpSender.WriteEmail
23
31
awaitemail.SendAsync();
24
32
```
25
33
26
-
An email must have a SMTP host address, a `From` and at least one `To` address; that's all. You can use each method as many times as you want, but setting a subject or body multiple times will overwrite previous subject or body values. The order of anything after WriteEmail does not matter.
27
-
Any issues will throw an exception, but you can also opt to just log them and continue with a `false` output:
34
+
Any configuration issues will throw an exception, but you can also opt to just log any exceptions and continue with a `false` output:
An email receiver must have a IMAP host address, a network credential, and a valid mail folder to read from.
110
+
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.
0 commit comments