CMailMessage::GetAuthenticationResults Method  
 
DWORD GetAuthenticationResults();

The GetAuthenticationResults method returns information about the authentication status of the message.

Parameters

None.

Return Value

This method returns one or more flags based on the value of the Authentication-Results header in the message. This method explicitly clears the last error code to assist in differentiating between an error condition, such as an invalid message handle, and when no authentication information was available. The following flags are defined:

Value Description
MIME_AUTH_NONE The message does not contain an Authentication-Results header or does not include any recognizable authentication types and their associated results.
MIME_AUTH_SPF_PASSED The message passed the Sender Policy Framework (SPF) check. The sender's IP address was authorized to send mail for the domain in the envelope sender address.
MIME_AUTH_SPF_FAILED The message failed the SPF check. The sending mail server is not authorized by the domain's SPF record to send mail on its behalf.
MIME_AUTH_DKIM_PASSED The message passed the DomainKeys Identified Mail (DKIM) check. The signature applied by the sender was successfully verified using the domain's public key.
MIME_AUTH_DKIM_FAILED The message failed the DKIM check. The signature could not be verified or did not match the message content, suggesting it may have been altered.
MIME_AUTH_DMARC_PASSED The message passed DMARC evaluation. The message aligned with a valid SPF or DKIM result based on the sender domain's policy.
MIME_AUTH_DMARC_FAILED The message failed DMARC evaluation. It did not pass SPF or DKIM checks in a way that aligns with the domain's published policy.
MIME_AUTH_TEMP_ERROR A temporary error occurred while evaluating one or more authentication mechanisms. This may indicate a DNS lookup timeout or other transient failure.
MIME_AUTH_PERM_ERROR A permanent error occurred during authentication checks. This may indicate a malformed DNS record or invalid message structure that prevents proper evaluation.

Remarks

Modern email systems use a set of authentication mechanisms to help verify that a message was sent from a legitimate source and not forged by a spammer or attacker. The GetAuthenticationResults method enables you to easily determine which of these mechanisms have passed a check and which of them have failed. It evaluates the following authentication information reported by the mail server:

SPF
Sender Policy Framework allows the owner of a domain to specify which mail servers are authorized to send email on its behalf. If the sending server is not listed in the domain's SPF record, the message may be marked as suspicious. SPF helps prevent spoofing of the envelope sender address, which is often used in phishing attacks.

DKIM
DomainKeys Identified Mail uses public-key cryptography to sign specific parts of the email, such as headers and body content. The signature is added by the sending mail server, and receiving systems use DNS to retrieve the sender's public key to verify that the message has not been tampered with. A valid DKIM signature helps confirm that the message was truly sent by the claimed domain.

DMARC
Domain-based Message Authentication, Reporting, and Conformance builds on SPF and DKIM by defining a policy for how a domain wants email receivers to handle messages that fail authentication checks. It also ensures that the visible From: address matches the domain that passed SPF or DKIM (a concept called alignment). DMARC allows domain owners to monitor abuse and enforce stronger protection against spoofing.

Checking these authentication results can help identify spoofed or forged messages, improve filtering decisions, and increase overall mail security. While not every legitimate message will have all three, failure of all mechanisms, especially from domains that publish strict DMARC policies, should be treated as suspicious.

While these authentication methods are useful signals, failing one of them does not necessarily mean a message is malicious. Many legitimate messages, even from well-known companies, may have misconfigured SPF records, missing DKIM signatures, or inconsistent DMARC policies. Conversely, a message that passes all checks could still be unwanted or deceptive. These results should be treated as advisory signals rather than absolute indicators of legitimacy. Developers are encouraged to consider authentication status alongside other factors, such as message content, sender reputation, and user reporting.

To simplify checking authentication outcomes, the following predefined flag combinations are also available:

  • MIME_AUTH_PASSED is a combination of all passing results (SPF, DKIM, DMARC).
  • MIME_AUTH_FAILED is a combination of all failing results.
  • MIME_AUTH_ERROR is a combination of temporary or permanent errors.

For a simplified boolean check using these flags, see the CheckAuthenticationResults method.

Example

if (mailMessage.Open(lpszFileName))
{
    // Get the authentication results for the message
    DWORD dwAuthFlags = mailMessage.GetAuthenticationResults();

    // Check if any of the SPF, DKIM, or DMARC checks failed
    if (dwAuthFlags & MIME_AUTH_FAILED)
        _tprintf(_T("This message has failed one or more authentication checks\n"));

    mailMessage.Close();
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csmsgv12.lib

See Also