Skip to content

Email Verifier Tool (MX, SPF, DMARC)

This tool verifies whether a domain is properly configured to send and receive emails by checking:

  • MX records (Mail Exchange)
  • SPF records
  • DMARC records

How It Works

1. MX Record Lookup

Checks whether the domain has Mail Exchange servers configured. If missing, the domain cannot receive emails.

2. SPF (Sender Policy Framework)

Searches for a TXT record starting with:

v=spf1

This defines which servers are allowed to send emails on behalf of the domain.

3. DMARC

Looks for a TXT record at:

_dmarc.<domain>

Starting with:

v=DMARC1

This instructs mail servers how to handle SPF/DKIM failures.


Implementation

package main

import (
    "bufio"
    "fmt"
    "log"
    "net"
    "os"
    "strings"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    fmt.Printf("domain, hasMX, hasSPF, spfRecord, hasDMARC, dmarcRecord\n")

    for scanner.Scan() {
        checkDomain(scanner.Text())
    }

    if err := scanner.Err(); err != nil {
        log.Fatal("Error: could not read from input: %v\n", err)
    }
}

func checkDomain(domain string) {
    var hasMX, hasSPF, hasDMARC bool
    var spfRecord, dmarcRecord string

    // Check MX Records
    mxRecords, err := net.LookupMX(domain)
    if err == nil && len(mxRecords) > 0 {
        hasMX = true
    }

    // Check SPF Records
    txtRecords, err := net.LookupTXT(domain)
    if err == nil {
        for _, record := range txtRecords {
            if strings.HasPrefix(record, "v=spf1") {
                hasSPF = true
                spfRecord = record
                break
            }
        }
    }

    // Check DMARC Records
    dmarcRecords, err := net.LookupTXT("_dmarc." + domain)
    if err == nil {
        for _, record := range dmarcRecords {
            if strings.HasPrefix(record, "v=DMARC1") {
                hasDMARC = true
                dmarcRecord = record
                break
            }
        }
    }

    fmt.Printf("%v, %v, %v, %v, %v, %v\n",
        domain, hasMX, hasSPF, spfRecord, hasDMARC, dmarcRecord)
}

Install dependency:

pip install dnspython
import dns.resolver
import sys

def check_domain(domain):
    has_mx = False
    has_spf = False
    has_dmarc = False
    spf_record = ""
    dmarc_record = ""

    # Check MX Records
    try:
        mx_answers = dns.resolver.resolve(domain, 'MX')
        if mx_answers:
            has_mx = True
    except Exception:
        pass

    # Check SPF Records
    try:
        txt_answers = dns.resolver.resolve(domain, 'TXT')
        for rdata in txt_answers:
            record = str(rdata).strip('"')
            if record.startswith("v=spf1"):
                has_spf = True
                spf_record = record
                break
    except Exception:
        pass

    # Check DMARC Records
    try:
        dmarc_answers = dns.resolver.resolve(f"_dmarc.{domain}", 'TXT')
        for rdata in dmarc_answers:
            record = str(rdata).strip('"')
            if record.startswith("v=DMARC1"):
                has_dmarc = True
                dmarc_record = record
                break
    except Exception:
        pass

    print(f"{domain}, {has_mx}, {has_spf}, {spf_record}, {has_dmarc}, {dmarc_record}")

def main():
    print("domain, hasMX, hasSPF, spfRecord, hasDMARC, dmarcRecord")
    for line in sys.stdin:
        domain = line.strip()
        if domain:
            check_domain(domain)

if __name__ == "__main__":
    main()

Example Usage

echo "google.com" | go run main.go

or

echo "google.com" | python verifier.py

Output Format

domain, hasMX, hasSPF, spfRecord, hasDMARC, dmarcRecord
google.com, true, true, v=spf1 include:_spf.google.com ~all, true, v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com