Skip to content

Commit 4a7f5e6

Browse files
committed
Merge branch 'features/readme'
2 parents 4d7b9fa + cc71741 commit 4a7f5e6

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,50 @@ curl --header "Content-Type: application/json" \
5252
--request POST \
5353
--data '{"email":"example@mail.ru","subject":"Confirm your email", "body":"Please visit this <a>link</a> to confirm your email."}' \
5454
http://localhost:5000/api/email/send
55+
```
56+
57+
## How to use RTUITLab.EmailService.Client package
58+
59+
1. Install [RTUITLab.EmailService.Client package](https://dev.azure.com/rtuitlab/RTU%20IT%20Lab/_packaging?_a=package&feed=ITLab&package=RTUITLab.EmailService.Client&protocolType=NuGet) to your ASP.Net Core project
60+
2. Extend your appsettings.json file with following code:
61+
```js
62+
{
63+
// configuration omitted
64+
"EmailSenderOptions": {
65+
"BaseAddress": "url to your email service that you've created upper. http://localhost:5000",
66+
"Key": "some random key for Header Authoriztion. Check instructions above"
67+
}
68+
// configuration omitted
69+
}
70+
```
71+
3. Edit Startup.cs file:
72+
```c#
73+
// Add email service
74+
services.AddEmailSender(Configuration
75+
.GetSection(nameof(EmailSenderOptions))
76+
.Get<EmailSenderOptions>());
77+
```
78+
4. By following code you'll send request to your email service. Email service will deliver emails:
79+
```c#
80+
RTUITLab.EmailService.Client.IEmailSender sender;
81+
await sender.SendEmailAsync("test@test.com", "Email letter subject", "<h1>Html body</h1>")
82+
```
83+
```c#
84+
// Example with some random controller
85+
public class EmailSendController : ControllerBase
86+
{
87+
private readonly RTUITLab.EmailService.Client.IEmailSender sender;
88+
89+
public EmailSender(RTUITLab.EmailService.Client.IEmailSender sender)
90+
{
91+
this.sender = sender;
92+
DoStuff();
93+
}
94+
95+
private async Task DoStuff()
96+
{
97+
// await sender.SendEmailAsync("email to send", "subject of email", "html body - message to send via email");
98+
await sender.SendEmailAsync("test@test.com", "Email letter subject", "<h1>Html body</h1>");
99+
}
100+
}
55101
```

0 commit comments

Comments
 (0)