diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs
index 0100633..7df6e36 100644
--- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs
+++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs
@@ -32,7 +32,7 @@ public class Smtp2GoProxy : IEmailServiceProxy
#region Constructors
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The HTTP client.
public Smtp2GoProxy(HttpClient httpClient)
@@ -83,27 +83,25 @@ public async Task SendEmail(Guid messageId,
StringContent content = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
- using(HttpClient client = new HttpClient())
- {
- client.BaseAddress = new Uri(ConfigurationReader.GetValue("SMTP2GoBaseAddress"));
-
- HttpResponseMessage httpResponse = await client.PostAsync("email/send", content, cancellationToken);
+ String requestUri = $"{ConfigurationReader.GetValue("SMTP2GoBaseAddress")}/email/send";
+ HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
+ requestMessage.Content = content;
- Smtp2GoSendEmailResponse apiResponse = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync());
+ HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken);
- Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");
+ Smtp2GoSendEmailResponse apiResponse = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync());
- // Translate the Response
- response = new EmailServiceProxyResponse
- {
- ApiStatusCode = httpResponse.StatusCode,
- EmailIdentifier = apiResponse.Data.EmailId,
- Error = apiResponse.Data.Error,
- ErrorCode = apiResponse.Data.ErrorCode,
- RequestIdentifier = apiResponse.RequestId
- };
- }
+ Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");
+ // Translate the Response
+ response = new EmailServiceProxyResponse
+ {
+ ApiStatusCode = httpResponse.StatusCode,
+ EmailIdentifier = apiResponse.Data.EmailId,
+ Error = apiResponse.Data.Error,
+ ErrorCode = apiResponse.Data.ErrorCode,
+ RequestIdentifier = apiResponse.RequestId
+ };
return response;
}
@@ -125,10 +123,13 @@ public async Task GetMessageStatus(String providerReferen
Smtp2GoEmailSearchRequest apiRequest = new Smtp2GoEmailSearchRequest
{
ApiKey = ConfigurationReader.GetValue("SMTP2GoAPIKey"),
- EmailId = new List{providerReference},
+ EmailId = new List
+ {
+ providerReference
+ },
StartDate = startDate.ToString("yyyy-MM-dd"),
EndDate = endDate.ToString("yyyy-MM-dd"),
- };
+ };
String requestSerialised = JsonConvert.SerializeObject(apiRequest);
@@ -136,29 +137,33 @@ public async Task GetMessageStatus(String providerReferen
StringContent content = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
- using (HttpClient client = new HttpClient())
- {
- client.BaseAddress = new Uri(ConfigurationReader.GetValue("SMTP2GoBaseAddress"));
+ String requestUri = $"{ConfigurationReader.GetValue("SMTP2GoBaseAddress")}/email/search";
+ HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
+ requestMessage.Content = content;
- HttpResponseMessage httpResponse = await client.PostAsync("email/search", content, cancellationToken);
+ HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken);
- Smtp2GoEmailSearchResponse apiResponse = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync());
+ Smtp2GoEmailSearchResponse apiResponse = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync());
- Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");
+ Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");
- // Translate the Response
- response = new MessageStatusResponse
- {
- ApiStatusCode = httpResponse.StatusCode,
- MessageStatus = this.TranslateMessageStatus(apiResponse.Data.EmailDetails.Single().Status),
- ProviderStatusDescription = apiResponse.Data.EmailDetails.Single().Status,
- Timestamp = apiResponse.Data.EmailDetails.Single().EmailStatusDate
- };
- }
+ // Translate the Response
+ response = new MessageStatusResponse
+ {
+ ApiStatusCode = httpResponse.StatusCode,
+ MessageStatus = this.TranslateMessageStatus(apiResponse.Data.EmailDetails.Single().Status),
+ ProviderStatusDescription = apiResponse.Data.EmailDetails.Single().Status,
+ Timestamp = apiResponse.Data.EmailDetails.Single().EmailStatusDate
+ };
return response;
}
+ ///
+ /// Translates the message status.
+ ///
+ /// The status.
+ ///
private MessageStatus TranslateMessageStatus(String status)
{
MessageStatus result;