DomainKeysVerify Method (MailMessage, Smtp, Header) |
Verifies the specified DomainKeys and/or DKIM signature of the mail message.
Namespace: MailBee.SecurityAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public DomainKeysVerifyResult Verify(
MailMessage msg,
Smtp dnsRequestor,
Header dkHeader
)
Public Function Verify (
msg As MailMessage,
dnsRequestor As Smtp,
dkHeader As Header
) As DomainKeysVerifyResult
Parameters
- msg
- Type: MailBee.MimeMailMessage
The mail message to be verified. - dnsRequestor
- Type: MailBee.SmtpMailSmtp
The instance of Smtp class to be used for making DNS queries. - dkHeader
- Type: MailBee.MimeHeader
The source message's DomainKey-Signature or DKIM-Signature to be verified.
Return Value
Type:
DomainKeysVerifyResultThe result of the verification.
Exceptions Remarks
This overload is useful if the message has multiple DKIM signatures and you want to verify them all.
Note |
---|
If the current system is FIPS-compliant and runs .NET 2.0/3.5 and the message contains only DKIM signature created using SHA256 algorithm,
the method will return Sha256NotSupported
or throw an exception if ThrowExceptions is enabled.
This can only occur with older .NET versions (before 4.0) because there was no FIPS-certified SHA256 implementation at that time.
On a FIPS system, use MailBee.NET.dll for .NET 4.0+ to avoid these issues.
All classic DK signatures and those DKIM signatures which use SHA1 algorithm are fully supported on all Windows platforms, including FIPS-compliant ones.
You'll still need to enable FipsMode to use FIPS-compliant versions of security algorithms. |
Examples
This sample loads an e-mail message from file, prepares
Smtp object for making
DNS queries and verifies all DKIM signatures in the message.
using System;
using MailBee;
using MailBee.Mime;
using MailBee.Security;
using MailBee.SmtpMail;
class Sample
{
static void Main(string[] args)
{
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\msg.eml");
Smtp mailer = new Smtp();
mailer.DnsServers.Autodetect();
DomainKeys dk = new DomainKeys();
HeaderCollection dkimHeaders = msg.Headers.Items("DKIM-Signature");
if (dkimHeaders == null)
{
Console.WriteLine("Message has no DKIM signatures");
}
else
{
foreach (Header h in dkimHeaders)
{
DomainKeysVerifyResult dkResult = dk.Verify(msg, mailer, h);
Console.WriteLine(dkResult.ToString());
}
}
}
}
Imports System
Imports MailBee
Imports MailBee.Mime
Imports MailBee.Security
Imports MailBee.SmtpMail
Module Sample
Sub Main(ByVal args As String())
Dim msg As MailMessage = New MailMessage
msg.LoadMessage("C:\Docs\msg.eml")
Dim mailer As Smtp = New Smtp
mailer.DnsServers.Autodetect()
Dim dk As DomainKeys = New DomainKeys
Dim dkimHeaders As HeaderCollection = msg.Headers.Items("DKIM-Signature")
If dkimHeaders Is Nothing Then
Console.WriteLine("Message has no DKIM signatures")
Else
For Each h As Header In dkimHeaders
Dim dkResult As DomainKeysVerifyResult = dk.Verify(msg, mailer, h)
Console.WriteLine(dkResult.ToString())
Next
End If
End Sub
End Module
See Also