-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(issue-162): add feature e-sender service to o2-auth
Merge pull request #169 from live-dev999/live-dev999/issue162
- Loading branch information
Showing
5 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/Services/auth/O2NextGen.Auth.Web/Services/ESenderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace O2NextGen.Auth.Web.Services | ||
{ | ||
public interface IESenderService | ||
{ | ||
Task Send(string email, string subject, string htmlMessage); | ||
} | ||
public class ESenderService: IESenderService | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly IOptions<UrlsConfig> _config; | ||
|
||
public ESenderService(HttpClient httpClient, IOptions<UrlsConfig> config) | ||
{ | ||
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); | ||
_config = config ?? throw new ArgumentNullException(nameof(config)); | ||
} | ||
|
||
public async Task Send(string email, string subject, string htmlMessage) | ||
{ | ||
var model = new MailRequestViewModel() | ||
{ | ||
Subject = subject, | ||
To = email, | ||
Body = htmlMessage | ||
}; | ||
var response = await _httpClient.PostAsJsonAsync("api/emailsender",model,CancellationToken.None); | ||
await response.Content.ReadAsAsync<MailRequestViewModel>(CancellationToken.None); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Services/auth/O2NextGen.Auth.Web/Services/MailRequestViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace O2NextGen.Auth.Web.Services | ||
{ | ||
public class MailRequestViewModel | ||
{ | ||
public long Id { get; set; } | ||
public string From { get; set; } | ||
public string To { get; set; } | ||
public string Body { get; set; } | ||
public string Subject { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace O2NextGen.Auth.Web.Services | ||
{ | ||
public class UrlsConfig | ||
{ | ||
public string ESenderUrl { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters