Skip to content
Menu

Is This Domain Protected From Email Spoofing - SPF, DKIM and DMARC Check

Reads MX, SPF, DMARC, DKIM, MTA-STS and TLS-RPT for up to 20 domains and gives each record a Pass, Warn, Fail or Info verdict, with the reason.

Is this domain protected from email spoofing - SPF, DKIM and DMARC check is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Is this domain protected from email spoofing - SPF, DKIM and DMARC check. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM or a user
NeedsPowerShell 5.1, the DnsClient module (Resolve-DnsName), internet DNS
Read-onlyReads, changes nothing

What It Does

The script is read-only. It asks DNS with Resolve-DnsName about each domain in Domain, up to 20, and writes one row per record found with a verdict of Pass, Warn, Fail or Info. It sends no email, connects to no mail server and needs no sign-in. It checks exactly the names it is given and does not guess a parent domain, so give it each domain you care about. A domain that does not exist ends with one row saying so.

SPF is the v=spf1 record. It is Pass for -all, Warn for ~all, and Fail for ?all, +all, no all term, no record, more than one record, or more than 10 DNS lookups, counted by following include and redirect. The deprecated ptr term turns a Pass into a Warn. DMARC is the record at _dmarc.[domain]: Pass for p=reject and for p=quarantine at 100 percent, Warn for p=none or quarantine on part of the mail, Fail for no record, an invalid one or two records. The detail says whether a report address (rua) is set.

DKIM keys cannot be listed from DNS, so it tries 16 common selector names, plus any you give in DkimSelectors, at [selector]._domainkey.[domain]. A key found is Pass, Warn when it is revoked or looks like 1024 bits, and Fail under 1024 bits. When none is found the row says Warn, because a selector the script does not know may still exist. The selector is in the DKIM-Signature header of a real email from the domain. MX shows where mail is received. MTA-STS and TLS-RPT are optional extras read from DNS only: the MTA-STS policy file on the web is not downloaded.

The run is OK whatever the verdicts are, and the answer counts the failures and warnings. If DNS itself cannot be reached the run ends in an error instead of guessing. DnsServer asks a specific resolver, such as a public one, instead of this PC's own.

Before You Run It

  • Give each domain you care about by name. A DMARC record on a parent domain protects its subdomains, but the script does not look there for you.
  • Find the DKIM selector in the DKIM-Signature header of a real email from the domain and pass it in DkimSelectors, or a DKIM Warn may only mean a selector it did not try.
  • Set DnsServer to a public resolver to see what the outside world sees, not this PC's own DNS.
  • Read the Warn rows too. p=none only watches, and spoofed mail is still delivered.
  • Read the row verdicts. An OK run can include Warn and Fail rows.

Type and Risk

  • Type: Report. It collects facts into a table and never alerts. It exits 0, or 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: 10 to 60 seconds per domain.
  • Example answer: "example.com: SPF -all; DMARC p=reject; DKIM 2 selector(s); 0 fail, 1 warn"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • Domain: The domain(s) to check, separated by commas, for example "example.com". Required. At most 20.
  • DkimSelectors: Extra DKIM selector names to try, separated by commas, for example "mailchimp, sig1". Default none.
  • DnsServer: IP address of a DNS server to ask instead of this PC's own, for example 1.1.1.1 to see what the public sees. Default empty = this PC's DNS.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

get-email-authentication-posture.ps1 · 1064 lines · 55.4 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.