From 5779fb8f54306d5397a37a3a29791ffc46a8941a Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Tue, 29 Nov 2022 16:26:17 +0900 Subject: feat: Brush up --- code/api/src/Services/MailService.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'code/api/src/Services') diff --git a/code/api/src/Services/MailService.cs b/code/api/src/Services/MailService.cs index d160762..6f9ff18 100644 --- a/code/api/src/Services/MailService.cs +++ b/code/api/src/Services/MailService.cs @@ -3,16 +3,14 @@ namespace IOL.GreatOffice.Api.Services; public class MailService { private readonly ILogger _logger; - private static string _postmarkToken; private static string _fromEmail; private readonly HttpClient _httpClient; public MailService(VaultService vaultService, ILogger logger, HttpClient httpClient) { var configuration = vaultService.GetCurrentAppConfiguration(); - _postmarkToken = configuration.POSTMARK_TOKEN; _fromEmail = configuration.EMAIL_FROM_ADDRESS; _logger = logger; - httpClient.DefaultRequestHeaders.Add("X-Postmark-Server-Token", _postmarkToken); + httpClient.DefaultRequestHeaders.Add("X-Postmark-Server-Token", configuration.POSTMARK_TOKEN); _httpClient = httpClient; } @@ -43,8 +41,7 @@ public class MailService if (message.HtmlBody.IsNullOrWhiteSpace() && message.TextBody.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(message), "Both HtmlBody and TextBody is empty, nothing to send"); } - - // TODO: Log response if unsuccessful + var response = await _httpClient.PostAsJsonAsync("https://api.postmarkapp.com/email", message); _logger.LogInformation("Postmark returned with message: {0}", (await response.Content.ReadFromJsonAsync()).Message); } catch (Exception e) { -- cgit v1.3