Skip to content

A .NET library providing utilities for mail such as DKIM, SPF and DMARC.

License

Notifications You must be signed in to change notification settings

markvantilburg/BusinessMonitor.MailTools

Repository files navigation

BusinessMonitor.MailTools

Test status Nuget

A .NET library providing utilities for mail such as DKIM, SPF and DMARC.

Usage

dotnet add package BusinessMonitor.MailTools

If you are using ASP.NET targeting .NET Framework you may need netstandard as reference in your web.config.

<assemblies>
    <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
</assemblies>

Resolver

To make this library independent of any DNS resolver implementation, we instead provide a IResolver interface. Each check class which needs to do lookups will require an instance of this interface, the user can then implement this interface with their own DNS library of choice.

public class DnsResolver : IResolver
{
    public string[] GetTextRecords(string domain)
    {
        // Your DNS resolve implementation goes here
    }
}

For an example implementation see BusinessMonitor.MailTools.Dns

Examples

Validate the DKIM record on a domain and return the public key:

var check = new DkimCheck(resolver);
var record = check.GetDkimRecord(domain, selector);

Console.WriteLine(record.PublicKey);

Parse a DMARC record:

var record = DmarcCheck.ParseDmarcRecord("v=DMARC1; p=reject; adkim=s; aspf=s");

Console.WriteLine(record.DkimMode);

Get a SPF record and return all includes:

var check = new SpfCheck(resolver);
var record = check.GetSpfRecord(domain);

foreach (var directive in record.Directives)
{
    if (directive.Mechanism == SpfMechanism.Include)
    {
        Console.WriteLine(directive.Include); // The include domain
        Console.WriteLine(directive.Included); // The included SPF record
    }
}

About

A .NET library providing utilities for mail such as DKIM, SPF and DMARC.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages