https://github.com/soenneker/soenneker.extensions.dtos.email
A collection of helpful EmailDto extension methods
https://github.com/soenneker/soenneker.extensions.dtos.email
attachment csharp dotnet dto dtos email emaildtosextension extension extensions
Last synced: 2 months ago
JSON representation
A collection of helpful EmailDto extension methods
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.extensions.dtos.email
- Owner: soenneker
- License: mit
- Created: 2025-03-21T14:39:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-21T00:34:52.000Z (2 months ago)
- Last Synced: 2026-04-21T02:43:35.057Z (2 months ago)
- Topics: attachment, csharp, dotnet, dto, dtos, email, emaildtosextension, extension, extensions
- Language: C#
- Homepage: https://soenneker.com
- Size: 738 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/soenneker.extensions.dtos.email/)
[](https://github.com/soenneker/soenneker.extensions.dtos.email/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/soenneker.extensions.dtos.email/)
[](https://github.com/soenneker/soenneker.extensions.dtos.email/actions/workflows/codeql.yml)
#  Soenneker.Extensions.Dtos.Email
### A collection of helpful EmailDto extension methods
## ?? Features
- Converts a well-defined `EmailDto` into a [MimeKit](https://github.com/jstedfast/MimeKit) `MimeMessage`
- Supports both `html` and `plain` formats
- Adds `To`, `Cc`, `Bcc`, and `Reply-To` addresses
- Automatically attaches files via `EmailAttachmentDto`
- Sets headers for `High` and `Low` priority emails
- Logs malformed recipients using `ILogger`
---
## ?? Validation
The extension validates:
- Required fields: `To`, `Subject`, and `Body`
- Non-null, non-whitespace addresses
- Optionally logs issues rather than throwing for individual recipient fields
---
## Installation
```
dotnet add package Soenneker.Extensions.Dtos.Email
```
---
## ?? Usage
```csharp
var mimeMessage = emailDto.ToMimeMessage(logger);
```
---
## ?? Example `EmailDto`
```csharp
var dto = new EmailDto
{
To = new List { "to@example.com" },
Cc = new List { "cc@example.com" },
Bcc = new List { "bcc@example.com" },
ReplyTo = "reply@example.com",
Name = "Sender Name",
Address = "sender@example.com",
Subject = "Test Subject",
Body = "
This is a test email.
",
Format = EmailFormat.Html,
Priority = EmailPriority.High,
Attachments = new List
{
new EmailAttachmentDto
{
FileName = "test.txt",
MimeType = "text/plain",
Data = Encoding.UTF8.GetBytes("Sample attachment content")
}
}
};
```