Skip to content

Commit e68daa5

Browse files
committed
Changed email contact format to ("me@example.com", "My Name") so it matches MailKit.
1 parent 2e73502 commit e68daa5

File tree

15 files changed

+457
-185
lines changed

15 files changed

+457
-185
lines changed

.github/workflows/_pipeline.yml

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@ on:
77
default: development
88
type: string
99

10-
# # Cancel any other running workflows with the same ID
11-
# concurrency:
12-
# group: ci-${{ inputs.environment }}-${{ github.ref }}
13-
# cancel-in-progress: true
14-
1510
# https://docs.github.com/en/actions/using-workflows/reusing-workflows
1611
jobs:
1712
version:
1813
uses: ./.github/workflows/_gitversion.yml
1914
secrets: inherit
2015

21-
build_core:
22-
needs: version
23-
uses: ./.github/workflows/_build-test.yml
24-
with:
25-
project-name: 'MailKitSimplified.Core'
26-
version: ${{ needs.version.outputs.version }}
27-
secrets: inherit
16+
# build_core:
17+
# needs: version
18+
# uses: ./.github/workflows/_build-test.yml
19+
# with:
20+
# project-name: 'MailKitSimplified.Core'
21+
# version: ${{ needs.version.outputs.version }}
22+
# secrets: inherit
2823

2924
build_sender:
3025
needs: version
@@ -34,23 +29,23 @@ jobs:
3429
version: ${{ needs.version.outputs.version }}
3530
secrets: inherit
3631

37-
build_receiver:
38-
needs: version
39-
uses: ./.github/workflows/_build-test.yml
40-
with:
41-
project-name: 'MailKitSimplified.Receiver'
42-
version: ${{ needs.version.outputs.version }}
43-
secrets: inherit
32+
# build_receiver:
33+
# needs: version
34+
# uses: ./.github/workflows/_build-test.yml
35+
# with:
36+
# project-name: 'MailKitSimplified.Receiver'
37+
# version: ${{ needs.version.outputs.version }}
38+
# secrets: inherit
4439

45-
deploy_core:
46-
# if: ${{ inputs.environment == 'release' }}
47-
needs: [version,build_core]
48-
uses: ./.github/workflows/_deploy-nuget.yml
49-
with:
50-
environment: ${{ inputs.environment }}
51-
project-name: 'MailKitSimplified.Core'
52-
version: ${{ needs.version.outputs.version }}
53-
secrets: inherit
40+
# deploy_core:
41+
# # if: ${{ inputs.environment == 'release' }}
42+
# needs: [version,build_core]
43+
# uses: ./.github/workflows/_deploy-nuget.yml
44+
# with:
45+
# environment: ${{ inputs.environment }}
46+
# project-name: 'MailKitSimplified.Core'
47+
# version: ${{ needs.version.outputs.version }}
48+
# secrets: inherit
5449

5550
deploy_sender:
5651
# if: ${{ inputs.environment == 'release' }}

.github/workflows/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
branches:
1010
- release/**
1111

12+
# Cancel any other running workflows with the same ID
13+
concurrency:
14+
group: cd-release-${{ github.ref }}
15+
cancel-in-progress: true
16+
1217
jobs:
1318
pipeline:
1419
name: 🪜 CI/CD

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MailKitSimplified [![Development](https://github.com/danzuep/MailKitSimplified/actions/workflows/development.yml/badge.svg)](https://github.com/danzuep/MailKitSimplified/actions/workflows/development.yml) [![Release](https://github.com/danzuep/MailKitSimplified/actions/workflows/release.yml/badge.svg)](https://github.com/danzuep/MailKitSimplified/actions/workflows/release.yml)
22

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!
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!
44

55
Sending an email is now as easy as:
66
```csharp
@@ -22,13 +22,12 @@ An email sender must have a SMTP host address, and sometimes a port number, but
2222
### Sending Mail
2323

2424
```csharp
25-
var email = smtpSender.WriteEmail
26-
.From("me@example.com")
27-
.To("you@example.com")
28-
.Subject("Hi")
29-
.Body("~");
30-
31-
await email.SendAsync();
25+
await smtpSender.WriteEmail
26+
.From("my.name@example.com")
27+
.To("YourName@example.com")
28+
.Subject("Hello World")
29+
.Attach(@"C:\Temp\EmailClientSmtp.log")
30+
.SendAsync();
3231
```
3332

3433
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
3736
bool isSent = await smtpSender.WriteEmail
3837
.From("me@example.com", "My Name")
3938
.To("you@example.com", "Your Name")
40-
.Cc("friend1@example.com")
41-
.Bcc("friend2@example.com")
42-
.Subject("Hey You")
43-
.Body($"Hello at {DateTime.Now}.")
44-
.Attach("C:/Temp/attachment1.txt", "C:/Temp/attachment2.pdf")
45-
.Attach("./attachment3.docx")
39+
.Cc("friend@example.com")
40+
.Bcc("admin@localhost")
41+
.Subject($"Hello at {DateTime.Now}!")
42+
.BodyText("Optional text/plain content.")
43+
.BodyHtml("Optional text/html content.</br>")
44+
.TryAttach("C:/Temp/attachment1.txt", "C:/Temp/attachment2.pdf")
4645
.TrySendAsync();
4746

4847
_logger.LogInformation("Email {result}.", isSent ? "sent" : "failed to send");
4948
```
5049

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).
5251

5352
### Dependency Injection
5453

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.
5655

5756
```csharp
5857
using MailKitSimplified.Sender.Extensions;
@@ -78,15 +77,15 @@ You'll also need the following in appsettings.json:
7877

7978
Other optional settings include SmtpPort, ProtocolLog, SmtpCredential:UserName and SmtpCredential:Password.
8079

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:
8281

8382
```csharp
8483
public class EmailService
8584
{
8685
private readonly IEmailWriter _writeEmail;
8786

88-
public EmailService(IEmailWriter emailWriter) {
89-
_writeEmail = emailWriter;
87+
public EmailService(IEmailWriter smtpSender) {
88+
_writeEmail = smtpSender;
9089
}
9190
}
9291
```
@@ -101,7 +100,7 @@ await _writeEmail.To("test@localhost").SendAsync();
101100

102101
### Setup
103102

104-
If you're not familiar with dependency injection then just use this:
103+
If you're not familiar with dependency injection then you can specify the IMAP host address like this:
105104

106105
```csharp
107106
using var imapReceiver = ImapReceiver.Create("imap.example.com", 0, "U5ern@me", "P@55w0rd");
@@ -111,6 +110,8 @@ An email receiver must have a IMAP host address, a network credential (unless yo
111110

112111
### Receiving Mail
113112

113+
This hasn't been published yet, but here's what I'm building at the moment:
114+
114115
```csharp
115116
var mailboxReceiver = imapReceiver
116117
.ReadFrom("INBOX")
@@ -126,4 +127,4 @@ var mimeMessageQueue = await imapReceiver
126127
.GetMimeMessagesAsync();
127128
```
128129

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).

samples/ConsoleServiceExample/Program.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
using Microsoft.Extensions.Logging;
2-
using MailKit;
1+
using MailKit;
2+
using Microsoft.Extensions.Logging;
3+
using Microsoft.Extensions.Options;
4+
using MailKitSimplified.Sender.Models;
35
using MailKitSimplified.Sender.Services;
46
using MailKitSimplified.Receiver.Services;
57
using MailKitSimplified.Receiver.Extensions;
68

79
using var loggerFactory = LoggerFactory.Create(_ => _.SetMinimumLevel(LogLevel.Trace).AddDebug().AddConsole());
810
var logger = loggerFactory.CreateLogger<Program>();
911

10-
using var smtpSender = SmtpSender.Create("localhost", 25);
11-
bool isSent = await smtpSender.WriteEmail
12-
.Bcc($"{Guid.NewGuid():N}@localhost")
12+
var senderOptions = Options.Create(new EmailSenderOptions(smtpHost: "localhost", smtpPort: 25));
13+
using var smtpSender = new SmtpSender(senderOptions, loggerFactory.CreateLogger<SmtpSender>());
14+
var writeEmail = smtpSender.WriteEmail;
15+
await writeEmail.To("test@localhost").SendAsync();
16+
bool isSent = await writeEmail
17+
.From("my.name@example.com")
18+
.To("YourName@example.com")
19+
.Subject("Hello World")
20+
.BodyText("Optional text/plain content.")
21+
.BodyHtml("Optional text/html content.</br>")
22+
.TryAttach(@"C:\Temp\EmailClientSmtp.log")
1323
.TrySendAsync();
1424

1525
logger.LogInformation("Email {result}.", isSent ? "sent" : "failed to send");
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32421.90
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Sender", "..\source\MailKitSimplified.Sender\MailKitSimplified.Sender.csproj", "{374BB83A-06BA-434A-9FB3-6F636506CD62}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Sender.Tests", "..\tests\MailKitSimplified.Sender.Tests\MailKitSimplified.Sender.Tests.csproj", "{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Receiver", "..\source\MailKitSimplified.Receiver\MailKitSimplified.Receiver.csproj", "{5C600194-3166-445F-86AE-3C249DDABDC9}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Receiver.Tests", "..\tests\MailKitSimplified.Receiver.Tests\MailKitSimplified.Receiver.Tests.csproj", "{9A773874-635F-40CF-8186-59ED9F7303A1}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleServiceExample", "ConsoleServiceExample\ConsoleServiceExample.csproj", "{D4E6836D-034D-419C-97A2-EA01BB3557B1}"
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Release|Any CPU = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{D4E6836D-034D-419C-97A2-EA01BB3557B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{D4E6836D-034D-419C-97A2-EA01BB3557B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{D4E6836D-034D-419C-97A2-EA01BB3557B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{D4E6836D-034D-419C-97A2-EA01BB3557B1}.Release|Any CPU.Build.0 = Release|Any CPU
42+
EndGlobalSection
43+
GlobalSection(SolutionProperties) = preSolution
44+
HideSolutionNode = FALSE
45+
EndGlobalSection
46+
GlobalSection(ExtensibilityGlobals) = postSolution
47+
SolutionGuid = {B5E640E9-B4E6-4555-8E04-FD16C3668769}
48+
EndGlobalSection
49+
EndGlobal

samples/MailKitSimplified.sln

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32421.90
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Core", "..\source\MailKitSimplified.Core\MailKitSimplified.Core.csproj", "{8A6F05EC-37CC-4E48-A28B-689BA9F80D0D}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Sender", "..\source\MailKitSimplified.Sender\MailKitSimplified.Sender.csproj", "{374BB83A-06BA-434A-9FB3-6F636506CD62}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Sender.Tests", "..\tests\MailKitSimplified.Sender.Tests\MailKitSimplified.Sender.Tests.csproj", "{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Receiver", "..\source\MailKitSimplified.Receiver\MailKitSimplified.Receiver.csproj", "{5C600194-3166-445F-86AE-3C249DDABDC9}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitSimplified.Receiver.Tests", "..\tests\MailKitSimplified.Receiver.Tests\MailKitSimplified.Receiver.Tests.csproj", "{9A773874-635F-40CF-8186-59ED9F7303A1}"
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Release|Any CPU = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{8A6F05EC-37CC-4E48-A28B-689BA9F80D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{8A6F05EC-37CC-4E48-A28B-689BA9F80D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{8A6F05EC-37CC-4E48-A28B-689BA9F80D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{8A6F05EC-37CC-4E48-A28B-689BA9F80D0D}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{374BB83A-06BA-434A-9FB3-6F636506CD62}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{A18AA6A6-D42B-44D9-8375-25C45B8B5C99}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{5C600194-3166-445F-86AE-3C249DDABDC9}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{9A773874-635F-40CF-8186-59ED9F7303A1}.Release|Any CPU.Build.0 = Release|Any CPU
42+
EndGlobalSection
43+
GlobalSection(SolutionProperties) = preSolution
44+
HideSolutionNode = FALSE
45+
EndGlobalSection
46+
GlobalSection(ExtensibilityGlobals) = postSolution
47+
SolutionGuid = {B5E640E9-B4E6-4555-8E04-FD16C3668769}
48+
EndGlobalSection
49+
EndGlobal

0 commit comments

Comments
 (0)