Skip to content

Commit

Permalink
Introduced deliverability reporting request/models
Browse files Browse the repository at this point in the history
  • Loading branch information
ey-mailosaur authored and jm-mailosaur committed Sep 30, 2024
1 parent 4ac2c69 commit f476184
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Mailosaur.Test/EmailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,43 @@ public void SpamAnalysisTest()
Assert.NotEmpty(rule.Description);
}
}

[Fact]
public void DeliverabilityReportTest()
{
var targetId = this.fixture.emails[0].Id;
DeliverabilityReport result = this.fixture.client.Analysis.Deliverability(targetId);

Assert.NotNull(result);
Assert.NotNull(result.Spf);
Assert.NotEmpty(result.Dkim);
foreach (var dkim in result.Dkim)
{
Assert.NotNull(dkim);
}
Assert.NotNull(result.Dmarc);

Assert.NotNull(result.BlockLists);
foreach (var blockList in result.BlockLists)
{
Assert.NotNull(blockList.Id);
Assert.NotNull(blockList.Name);
}

Assert.NotNull(result.Content);

Assert.NotNull(result.DnsRecords);
Assert.NotNull(result.DnsRecords.A);
Assert.NotNull(result.DnsRecords.MX);
Assert.NotNull(result.DnsRecords.PTR);

Assert.NotNull(result.SpamAssassin);
foreach (SpamAssassinRule rule in result.SpamAssassin.Rules)
{
Assert.NotEmpty(rule.Rule);
Assert.NotEmpty(rule.Description);
}
}

[Fact]
public void DeleteTest()
Expand Down
9 changes: 9 additions & 0 deletions Mailosaur/Models/BlockListResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Mailosaur.Models
{
public class BlockListResult
{
public string Id { get; set; }
public string Name { get; set; }
public ResultEnum Result { get; set; }
}
}
15 changes: 15 additions & 0 deletions Mailosaur/Models/Content.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Mailosaur.Models
{
public class Content
{
public bool Embed { get; set; }
public bool Iframe { get; set; }
public bool Object { get; set; }
public bool Script { get; set; }
public bool ShortUrls { get; set; }
public int TextSize { get; set; }
public int TotalSize { get; set; }
public bool MissingAlt { get; set; }
public bool MissingListUnsubscribe { get; set; }
}
}
15 changes: 15 additions & 0 deletions Mailosaur/Models/DeliverabilityReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Mailosaur.Models
{
public class DeliverabilityReport
{
public EmailAuthenticationResult Spf { get; set; }
public List<EmailAuthenticationResult> Dkim { get; set; }
public EmailAuthenticationResult Dmarc { get; set; }
public List<BlockListResult> BlockLists { get; set; }
public Content Content { get; set; }
public DnsRecords DnsRecords { get; set; } = new DnsRecords();
public SpamAssassinResult SpamAssassin { get; set; }
}
}
11 changes: 11 additions & 0 deletions Mailosaur/Models/DnsRecords.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace Mailosaur.Models
{
public class DnsRecords
{
public List<string> A { get; set; }
public List<string> MX { get; set; }
public List<string> PTR { get; set; }
}
}
13 changes: 13 additions & 0 deletions Mailosaur/Models/EmailAuthenticationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;

namespace Mailosaur.Models
{
public class EmailAuthenticationResult
{
public ResultEnum Result { get; set; }
public String Description { get; set; }
public string RawValue { get; set; }
public Dictionary<string, string> Tags { get; set; } = new Dictionary<string, string>();
}
}
10 changes: 10 additions & 0 deletions Mailosaur/Models/ResultEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Mailosaur.Models
{
public enum ResultEnum
{
Pass,
Warning,
Fail,
Timeout
}
}
11 changes: 11 additions & 0 deletions Mailosaur/Models/SpamAssassinResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace Mailosaur.Models
{
public class SpamAssassinResult
{
public int Score { get; set; }
public ResultEnum Result { get; set; }
public List<SpamAssassinRule> Rules { get; set; }
}
}
24 changes: 24 additions & 0 deletions Mailosaur/Operations/Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,29 @@ public SpamAnalysisResult Spam(string email)
/// </param>
public Task<SpamAnalysisResult> SpamAsync(string email)
=> ExecuteRequest<SpamAnalysisResult>(HttpMethod.Get, $"api/analysis/spam/{email}");

/// <summary>
/// Perform a deliverability test
/// </summary>
/// <remarks>
/// Perform deliverability testing on the specified email
/// </remarks>
/// <param name='email'>
/// The identifier of the email to be analyzed.
/// </param>
public DeliverabilityReport Deliverability(string email)
=> Task.Run<DeliverabilityReport>(async () => await DeliverabilityAsync(email)).Result;

/// <summary>
/// Perform a deliverability test
/// </summary>
/// <remarks>
/// Perform deliverability testing on the specified email
/// </remarks>
/// <param name='email'>
/// The identifier of the email to be analyzed.
/// </param>
public Task<DeliverabilityReport> DeliverabilityAsync(string email)
=> ExecuteRequest<DeliverabilityReport>(HttpMethod.Get, $"api/analysis/deliverability/{email}");
}
}

0 comments on commit f476184

Please sign in to comment.