Skip to content

Commit 0876068

Browse files
committed
Merge latest main
2 parents c6dd877 + 50b51ff commit 0876068

File tree

345 files changed

+1059
-2613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

345 files changed

+1059
-2613
lines changed

.editorconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ trim_trailing_whitespace = false
5252
[*.cs]
5353

5454
# License header
55-
file_header_template = -----------------------------------------------------------------------\n<copyright file="{fileName}" company="Railsware Products Studio, LLC">\nCopyright (c) Railsware Products Studio, LLC. All rights reserved.\n</copyright>\n-----------------------------------------------------------------------
55+
file_header_template = unset
56+
# -----------------------------------------------------------------------\n<copyright file="{fileName}" company="Railsware Products Studio, LLC">\nCopyright (c) Railsware Products Studio, LLC. All rights reserved.\n</copyright>\n-----------------------------------------------------------------------
5657

5758
# New line preferences
5859
csharp_new_line_before_open_brace = all
@@ -98,6 +99,7 @@ csharp_prefer_simple_using_statement = true:suggestion
9899
csharp_style_prefer_switch_expression = true:suggestion
99100
csharp_style_namespace_declarations = file_scoped:suggestion
100101
dotnet_style_readonly_field = true:suggestion
102+
dotnet_style_require_accessibility_modifiers = always:suggestion
101103

102104
# Expression-level preferences
103105
dotnet_style_object_initializer = true:suggestion
@@ -111,6 +113,7 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
111113
dotnet_style_prefer_auto_properties = true:suggestion
112114
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
113115
dotnet_style_prefer_conditional_expression_over_return = true:silent
116+
dotnet_style_prefer_collection_expression = false:suggestion
114117
csharp_prefer_simple_default_expression = true:suggestion
115118
csharp_style_prefer_top_level_statements = true:silent
116119

@@ -274,7 +277,7 @@ dotnet_diagnostic.IDE0045.severity = suggestion
274277
dotnet_diagnostic.IDE0046.severity = suggestion
275278

276279
# IDE0058: Expression value is never used
277-
dotnet_diagnostic.IDE0058.severity = suggestion
280+
dotnet_diagnostic.IDE0058.severity = silent
278281

279282

280283
# CA1032: Implement standard exception constructors

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These owners will be the default owners for everything in
2+
# the repo. Unless a later match takes precedence, they will be
3+
# requested for review when someone opens a pull request.
4+
* @zhaparoff @mklocek @vittorius

.github/pull_request_template.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
## Motivation
22

33

4-
## Description of Changes
5-
6-
7-
## Checklist
8-
- [ ] Acknowledged that contribution is made under the project's [LICENSE](https://github.com/mailtrap/mailtrap-dotnet/blob/main/LICENSE.md)
9-
- [ ] Confirmed that PR and code/documentation changes are following the [Contributor Code of Conduct](https://github.com/mailtrap/mailtrap-dotnet/blob/main/CODE_OF_CONDUCT.md)
10-
- [ ] PR is properly titled and contains the summary of changes introduced
11-
- [ ] PR branch is based on the latest main branch commit
12-
- [ ] PR contains some meaningful changes, including, but not limited to: functionality, tests, documentation, spelling, etc.
13-
- [ ] Added/updated XMLDoc and inline comments in the code, according to the changes made
14-
- [ ] Added/updated unit tests for added/changed functionality (if any)
15-
- [ ] Added/updated documentation files (if applicable)
4+
## Changes
5+
6+
- Change 1
7+
- Change 2
8+
9+
## How to test
10+
11+
- [ ] Test 1
12+
- [ ] Test 2
13+
14+
## Images and GIFs
15+
16+
| Before | After |
17+
|--------|--------|
18+
| link1 | link2 |
19+
| link3 | link4 |
20+
| link5 | link6 |
21+
| link7 | link8 |
22+
| link9 | link10 |

CONTRIBUTING.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Contributing to Mailtrap .NET Client
2+
First of all, thank you for considering contributing to Mailtrap .NET Client!
3+
We are excited to have you here :tada:
4+
Any contribution is welcome and appreciated, be it a bug report, a feature request, a documentation update, or a code change.
5+
6+
7+
## Code of Conduct
8+
This project and everyone participating in it is governed by the [Code of Conduct](CODE_OF_CONDUCT.md).
9+
By participating, you are expected to uphold this code.
10+
Please report unacceptable behavior to [[email protected]](mailto:[email protected]).
11+
12+
13+
## License
14+
This project is licensed under the [MIT License](LICENSE.md).
15+
Please consider that your contributions should meet its terms and conditions.
16+
Also, by participating, you give your permission to license your contributions into this project under its terms and conditions.
17+
18+
19+
## Report an issue or propose improvement
20+
Kindly consider searching for already existing issue or feature proposal before creating a new one.
21+
Do not increase the entropy unnecessarily - the Universe will appreciate it.
22+
23+
If it is still the case - please use [Issues](https://github.com/railsware/mailtrap-dotnet/issues) section of the repo to file an issue,
24+
possible improvement or feature proposal.
25+
26+
27+
## Contribute to the code or documentation
28+
29+
### Prerequisites
30+
To be able to make edits, build and run your changes locally, you will need the following:
31+
- Code editor or IDE of your choice, with C# language and .NET 9.x support.
32+
This repository uses [EditorConfig](https://aka.ms/editorconfigdocs) settings to enforce consistent code style,
33+
thus usage of editor which respects them is highly encouraged.
34+
[Visual Studio 2022](https://visualstudio.microsoft.com/) is one of recommended options.
35+
36+
- [.NET SDK v9.x](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
37+
38+
- Plain text editor of your choice - for documentation updates.
39+
Ideally, with [Markdown](https://en.wikipedia.org/wiki/Markdown) support.
40+
41+
- [docfx](https://dotnet.github.io/docfx/docs/) - to build and validate documentation website.
42+
43+
44+
### Pull requests
45+
Please consider that contributions to the repository content are managed through pull requests.
46+
Thus you will need to follow steps below to create a new one:
47+
48+
1. Clone the repo
49+
```bat
50+
git clone https://github.com/railsware/mailtrap-dotnet.git
51+
```
52+
53+
2. Create new branch
54+
```bat
55+
git checkout -b <branch-name>
56+
```
57+
Please consider using the following pattern for branch naming:
58+
`[change-type]/[issue-id]-[change-description]`
59+
where:
60+
`[change-type]` - one of the following: `feat[ure]`, `fix`, `docs`, `devops`, `test`, `refactor`, etc.
61+
`[issue-id]` - numeric ID of the issue that you are going to address, if available.
62+
`[change-description]` - short description of the change, in [kebab-case](https://en.wikipedia.org/wiki/Letter_case#Kebab_case)
63+
64+
3. Make changes, validate them.
65+
66+
4. Create commits with a description of changes made.
67+
Usage of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) is encouraged.
68+
69+
5. Push to the remote.
70+
71+
6. Finally, create a pull request to the [main](https://github.com/railsware/mailtrap-dotnet/tree/main) branch,
72+
using the template provided.
73+
Please consider providing detailed description what was changed and validating PR checklist to streamline the PR review.
74+
75+
76+
### Code
77+
This SDK is targeting [.NET Standard 2.0](https://dotnet.microsoft.com/platform/dotnet-standard#versions)
78+
thus not all latest C# language features are supported.
79+
Only C# v7.3 features support is guaranteed.
80+
Later version features should be used with care and their runtime behavior should be thoroughly tested.
81+
82+
Adding unit/integration tests is encouraged for every added/changed functionality.
83+
Although we are not targeting 100% coverage, ensuring everything is working as expected is important.
84+
85+
86+
### Documentation
87+
You can improve SDK documentation in several ways.
88+
89+
#### Add or extend [XMLDoc](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/) comments in the code
90+
They are used to show inline help in IDE and to generate SDK API reference section of documentation website,
91+
thus are a crucial part of the SDK.
92+
93+
#### Update markdown files in the [docs](https://github.com/railsware/mailtrap-dotnet/tree/main/docs) folder of the repo.
94+
Considering that [docfx](https://dotnet.github.io/docfx/docs/basic-concepts.html) tool is used to create documentation website
95+
from sources, please ensure that you are using [supported syntax](https://dotnet.github.io/docfx/docs/markdown.html).
96+
97+
To build and verify documentation locally, before committing your changes:
98+
1. Install/update `docfx` as a global tool
99+
```bat
100+
dotnet tool (install|update) -g docfx
101+
```
102+
2. Build and serve documentation website
103+
```bat
104+
cd <repository-path>
105+
docfx docs/docfx.json --serve
106+
```
107+
3. Finally, open <http://localhost:8080> in your browser and navigate to the changed section.

Directory.Packages.props

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
<ItemGroup>
66
<!-- MS -->
77
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
8-
<PackageVersion Include="Microsoft.DotNet.ApiCompat.Task" Version="9.0.101" />
9-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
10-
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
11-
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
12-
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
8+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.7" />
9+
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.7" />
10+
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.7.0" />
11+
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.7" />
1312
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
1413
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
15-
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
14+
<PackageVersion Include="System.Text.Json" Version="9.0.7" />
1615
<!-- 3rd party -->
1716
<PackageVersion Include="FluentValidation" Version="11.11.0" />
18-
<PackageVersion Include="MinVer" Version="6.0.0" />
19-
<!--Testing -->
20-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
21-
<PackageVersion Include="NUnit" Version="4.2.2" />
22-
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0" />
23-
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
24-
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
17+
<!-- Testing -->
18+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
19+
<PackageVersion Include="NUnit" Version="4.3.2" />
20+
<PackageVersion Include="NUnit.Analyzers" Version="4.9.2" />
21+
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
22+
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
2523
<PackageVersion Include="Moq" Version="4.20.72" />
2624
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0" />
27-
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
25+
<!-- Do NOT update FluentAssertions to major version 8 and above, since it does not provide permissive license anymore -->
26+
<!-- https://github.com/fluentassertions/fluentassertions/issues/2955 -->
27+
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
2828
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.34.1" />
2929
</ItemGroup>
3030
</Project>

Mailtrap.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{CD08E7CB-C
5454
ProjectSection(SolutionItems) = preProject
5555
CHANGELOG.md = CHANGELOG.md
5656
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
57+
CONTRIBUTING.md = CONTRIBUTING.md
5758
LICENSE.md = LICENSE.md
5859
README.md = README.md
5960
EndProjectSection

README.md

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,123 @@
1-
# Official Mailtrap .NET Client
1+
![Mailtrap](assets/img/mailtrap-logo.svg)
22

3+
[![NuGet Version](https://img.shields.io/nuget/v/Railsware.Mailtrap?label=NuGet)](https://www.nuget.org/packages/Railsware.Mailtrap)
34
[![CI](https://github.com/railsware/mailtrap-dotnet/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/railsware/mailtrap-dotnet/actions/workflows/build.yml)
45
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/railsware/mailtrap-dotnet/blob/main/LICENSE.md)
56

6-
## Summary
7-
This is the official .NET client for [Mailtrap](https://mailtrap.io/)
7+
# Official Mailtrap .NET Client
8+
Welcome to the official [Mailtrap](https://mailtrap.io/) .NET Client repository.
9+
This client allows you to quickly and easily integrate your .NET application with **v2.0** of the [Mailtrap API](https://api-docs.mailtrap.io/docs/mailtrap-api-docs/5tjdeg9545058-mailtrap-api).
10+
11+
12+
## Quick Start
13+
The following few simple steps will bring Mailtrap API functionality into your .NET project.
14+
15+
### Prerequisites
16+
- Please ensure your project targets .NET implementation which supports [.NET Standard 2.0](https://dotnet.microsoft.com/platform/dotnet-standard#versions) specification.
17+
18+
- Register new or log into existing account at [mailtrap.io](https://mailtrap.io/register/signup?ref=maitrap-dotnet)
19+
20+
- Obtain [API token](https://mailtrap.io/api-tokens)
21+
You can use one of the existing or create a new one.
22+
23+
### Install
24+
Install `Mailtrap` package from NuGet
25+
26+
> **TODO**
27+
> This is an example command, to be updated once the package is published.
28+
29+
```console
30+
dotnet add package Mailtrap
31+
```
32+
33+
### Configure
34+
Add Mailtrap services to the DI container.
35+
36+
```csharp
37+
using Mailtrap;
38+
39+
...
40+
41+
hostBuilder.ConfigureServices((context, services) =>
42+
{
43+
services.AddMailtrapClient(options =>
44+
{
45+
// Definitely, hardcoding a token isn't a good idea.
46+
// This example uses it for simplicity, but in real-world scenarios
47+
// you should consider more secure approaches for storing secrets.
48+
49+
// Environment variables can be an option, as well as other solutions:
50+
// https://learn.microsoft.com/aspnet/core/security/app-secrets
51+
// or https://learn.microsoft.com/aspnet/core/security/key-vault-configuration
52+
options.ApiToken = "<API_TOKEN>";
53+
});
54+
});
55+
```
56+
57+
### Use
58+
Now you can inject `IMailtrapClient` instance in any application service and use it to make API calls.
59+
60+
```csharp
61+
using Mailtrap;
62+
using Mailtrap.Emails.Requests;
63+
using Mailtrap.Emails.Responses;
64+
65+
66+
namespace MyAwesomeProject;
67+
68+
69+
public sealed class SendEmailService : ISendEmailService
70+
{
71+
private readonly IMailtrapClient _mailtrapClient;
72+
73+
74+
public SendEmailService(IMailtrapClient mailtrapClient)
75+
{
76+
_mailtrapClient = client;
77+
}
78+
79+
80+
public async Task DoWork()
81+
{
82+
try
83+
{
84+
SendEmailRequest request = SendEmailRequest
85+
.Create()
86+
.From("[email protected]", "John Doe")
87+
88+
.Subject("Invitation to Earth")
89+
.Text("Dear Bill,\n\nIt will be a great pleasure to see you on our blue planet next weekend.\n\nBest regards, John.");
90+
91+
SendEmailResponse response = await _mailtrapClient
92+
.Email()
93+
.Send(request);
94+
95+
string messageId = response.MessageIds.FirstOrDefault();
96+
}
97+
catch (MailtrapException mtex)
98+
{
99+
// handle Mailtrap API specific exceptions
100+
}
101+
catch (OperationCancelledException ocex)
102+
{
103+
// handle cancellation
104+
}
105+
catch (Exception ex)
106+
{
107+
// handle other exceptions
108+
}
109+
}
110+
}
111+
```
112+
113+
## Documentation
114+
Please visit [Documentation Portal](https://railsware.github.io/mailtrap-dotnet/) for detailed setup, configuration and usage instructions.
115+
A bunch of examples is available [here](https://github.com/railsware/mailtrap-dotnet/tree/main/examples).
116+
117+
118+
## Contributing
119+
We believe in the power of OSS and welcome any contributions to the library.
120+
Please refer to [Contributing Guide](CONTRIBUTING.md) for details.
8121

9-
It works with the second version of [Mailtrap API](https://api-docs.mailtrap.io/docs/mailtrap-api-docs/5tjdeg9545058-mailtrap-api)
122+
## License
123+
Licensed under the [MIT License](LICENSE.md).

docs/cookbook/send-email.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var from = new EmailAddress("[email protected]", "John Doe");
4040
var request = new SendEmailRequest
4141
{
4242
From = from,
43+
ReplyTo = new EmailAddress("[email protected]"),
4344
Subject = "Invitation to Earth",
4445
TextBody = "Dear Bill,\n\nIt will be a great pleasure to see you on our blue planet next weekend.\n\nBest regards, John."
4546
};
@@ -130,6 +131,9 @@ var request = SendEmailRequest.Create();
130131
// Sender (Display name is optional)
131132
request.From("[email protected]", "John Doe");
132133

134+
// Reply To (Display name is optional)
135+
request.ReplyTo("[email protected]");
136+
133137
// You can use simple email as recipient
134138
request.To("[email protected]");
135139

0 commit comments

Comments
 (0)