Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;


/// <summary>
///
/// </summary>
[ExcludeFromCodeCoverage]
public class Data
{
/// <summary>
/// Gets or sets the count.
/// </summary>
/// <value>
/// The count.
/// </value>
[JsonProperty("count")]

public Int32 Count { get; set; }

/// <summary>
/// Gets or sets the email details.
/// </summary>
/// <value>
/// The email details.
/// </value>
[JsonProperty("emails")]
public List<EmailDetails> EmailDetails { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,20 @@
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

/// <summary>
///
/// </summary>
[ExcludeFromCodeCoverage]
public class EmailDetails
{
/// <summary>
/// Gets or sets the subject.
/// </summary>
/// <value>
/// The subject.
/// </value>
[JsonProperty("subject")]
public String Subject { get; set; }

/// <summary>
/// Gets or sets the delivered at.
/// </summary>
/// <value>
/// The delivered at.
/// </value>
[JsonProperty("delivered_at")]
public DateTime DeliveredAt { get; set; }

/// <summary>
/// Gets or sets the email status date.
/// </summary>
/// <value>
/// The email status date.
/// </value>
[JsonProperty("email_ts")]
public DateTime EmailStatusDate { get; set; }

/// <summary>
/// Gets or sets the process status.
/// </summary>
/// <value>
/// The process status.
/// </value>
[JsonProperty("process_status")]
public String ProcessStatus { get; set; }

/// <summary>
/// Gets or sets the email identifier.
/// </summary>
/// <value>
/// The email identifier.
/// </value>
[JsonProperty("email_id")]
public String EmailId { get; set; }

/// <summary>
/// Gets or sets the status.
/// </summary>
/// <value>
/// The status.
/// </value>
[JsonProperty("status")]
public String Status { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;



[ExcludeFromCodeCoverage]
public class Smtp2GoAttachment
{
#region Properties

[JsonProperty("fileblob")]
public String FileBlob { get; set; }

[JsonProperty("filename")]
public String FileName { get; set; }

[JsonProperty("mimetype")]
public String MimeType { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

/// <summary>
///
/// </summary>

[ExcludeFromCodeCoverage]
public class Smtp2GoEmailSearchRequest
{
/// <summary>
/// Gets or sets the email identifier.
/// </summary>
/// <value>
/// The email identifier.
/// </value>
[JsonProperty("email_id")]
public List<String> EmailId { get; set; }

/// <summary>
/// Gets or sets the API key.
/// </summary>
/// <value>
/// The API key.
/// </value>
[JsonProperty("api_key")]
public String ApiKey { get; set; }

/// <summary>
/// Gets or sets the start date.
/// </summary>
/// <value>
/// The start date.
/// </value>
[JsonProperty("start_date")]
public String StartDate { get; set; }

/// <summary>
/// Gets or sets the end date.
/// </summary>
/// <value>
/// The end date.
/// </value>
[JsonProperty("end_date")]
public String EndDate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,12 @@
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

/// <summary>
///
/// </summary>

[ExcludeFromCodeCoverage]
public class Smtp2GoEmailSearchResponse
{
#region Properties

/// <summary>
/// Gets or sets the data.
/// </summary>
/// <value>
/// The data.
/// </value>
[JsonProperty("data")]
public Data Data { get; set; }

/// <summary>
/// Gets or sets the request identifier.
/// </summary>
/// <value>
/// The request identifier.
/// </value>
[JsonProperty("request_id")]
public String RequestId { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace MessagingService.BusinessLogic.Services.EmailServices.Smtp2Go
using Shared.Serialisation;

namespace MessagingService.BusinessLogic.Services.EmailServices.Smtp2Go
{
using Models;
using Newtonsoft.Json;
using Service.Services.Email.Smtp2Go;
using Shared.General;
using Shared.Logger;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -73,7 +72,7 @@ public async Task<EmailServiceProxyResponse> SendEmail(Guid messageId,
attachments.ForEach(a => apiRequest.Attachments.Add(new Smtp2GoAttachment { FileBlob = a.FileData, FileName = a.Filename, MimeType = this.ConvertFileType(a.FileType) }));
}

String requestSerialised = JsonConvert.SerializeObject(apiRequest, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None });
String requestSerialised = StringSerialiser.Serialise(apiRequest, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase, WriteIndented:true));

Logger.LogDebug($"Request Message Sent to Email Provider [SMTP2Go] {requestSerialised}");

Expand All @@ -86,12 +85,11 @@ public async Task<EmailServiceProxyResponse> SendEmail(Guid messageId,
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken);

Smtp2GoSendEmailResponse apiResponse = httpResponse.IsSuccessStatusCode switch {
true => JsonConvert.DeserializeObject<Smtp2GoSendEmailResponse>(await httpResponse.Content.ReadAsStringAsync(cancellationToken)),
true => StringSerialiser.Deserialise<Smtp2GoSendEmailResponse>(await httpResponse.Content.ReadAsStringAsync(cancellationToken)),
_ => new Smtp2GoSendEmailResponse { Data = new Smtp2GoSendEmailResponseData { Error = httpResponse.StatusCode.ToString(), ErrorCode = ((Int32)httpResponse.StatusCode).ToString() } }
};

Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");

Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {StringSerialiser.Serialise(apiResponse)}");
// Translate the Response
return new EmailServiceProxyResponse {
ApiCallSuccessful = httpResponse.IsSuccessStatusCode && String.IsNullOrEmpty(apiResponse.Data.ErrorCode),
Expand Down Expand Up @@ -119,7 +117,7 @@ public async Task<MessageStatusResponse> GetMessageStatus(String providerReferen
ApiKey = Configuration.APIKey, EmailId = new List<String> { providerReference }, StartDate = startDate.ToString("yyyy-MM-dd"), EndDate = endDate.ToString("yyyy-MM-dd"),
};

String requestSerialised = JsonConvert.SerializeObject(apiRequest, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None });
String requestSerialised = StringSerialiser.Serialise(apiRequest, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase, WriteIndented: true));

Logger.LogDebug($"Request Message Sent to Email Provider [SMTP2Go] {requestSerialised}");

Expand All @@ -131,9 +129,9 @@ public async Task<MessageStatusResponse> GetMessageStatus(String providerReferen

HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken);

Smtp2GoEmailSearchResponse apiResponse = JsonConvert.DeserializeObject<Smtp2GoEmailSearchResponse>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
Smtp2GoEmailSearchResponse apiResponse = StringSerialiser.Deserialise<Smtp2GoEmailSearchResponse>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));

Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}");
Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {StringSerialiser.Serialise(apiResponse)}");

// Translate the Response
return 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 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Newtonsoft.Json;

namespace MessagingService.Service.Services.Email.Smtp2Go
{
Expand All @@ -9,95 +8,24 @@ namespace MessagingService.Service.Services.Email.Smtp2Go
[ExcludeFromCodeCoverage]
public class Smtp2GoSendEmailRequest
{
/// <summary>
/// Gets or sets the API key.
/// </summary>
/// <value>
/// The API key.
/// </value>
[JsonProperty("api_key")]
public String ApiKey { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [test mode].
/// </summary>
/// <value>
/// <c>true</c> if [test mode]; otherwise, <c>false</c>.
/// </value>
[JsonProperty("test")]
public Boolean TestMode { get; set; }

/// <summary>
/// Gets or sets the sender.
/// </summary>
/// <value>
/// The sender.
/// </value>
[JsonProperty("sender")]
public String Sender { get; set; }

/// <summary>
/// Gets or sets to.
/// </summary>
/// <value>
/// To.
/// </value>
[JsonProperty("to")]
public String[] To { get; set; }

/// <summary>
/// Gets or sets the cc.
/// </summary>
/// <value>
/// The cc.
/// </value>
[JsonProperty("cc")]
public String[] CC { get; set; }

/// <summary>
/// Gets or sets the BCC.
/// </summary>
/// <value>
/// The BCC.
/// </value>
[JsonProperty("bcc")]
public String[] BCC { get; set; }

/// <summary>
/// Gets or sets the subject.
/// </summary>
/// <value>
/// The subject.
/// </value>
[JsonProperty("subject")]
public String Subject { get; set; }

/// <summary>
/// Gets or sets the HTML body.
/// </summary>
/// <value>
/// The HTML body.
/// </value>
[JsonProperty("html_body")]
public String HTMLBody { get; set; }

/// <summary>
/// Gets or sets the text body.
/// </summary>
/// <value>
/// The text body.
/// </value>
[JsonProperty("text_body")]
public String TextBody { get; set; }

/// <summary>
/// Gets or sets the attachments.
/// </summary>
/// <value>
/// The attachments.
/// </value>
[JsonProperty("attachments")]
public List<Smtp2GoAttachment> Attachments { get; set; }

}
}
Loading
Loading