——
LabLABS

Audit your own mail domain with dig, OpenSSL and swaks

Use a controlled lab workflow to inspect MX, SPF, DKIM, DMARC and STARTTLS for a domain you own, send an authorised test message, and interpret what the evidence does—and does not—prove.

Use a controlled lab workflow to inspect MX, SPF, DKIM, DMARC and STARTTLS for a domain you own, send an authorised test message, and interpret what the evidence does—and does not—prove.

email securityDNSSPFDKIMDMARCSTARTTLSdigOpenSSLswaks

Learning objectives

By the end of this lab, you will be able to collect reproducible evidence for a mail domain you control: its MX routing, SPF policy, DKIM selector, DMARC policy and SMTP STARTTLS certificate. You will then send one authorised test message with swaks and read the authentication results without confusing deliverability with security.

This is a Lab, not a red-team exercise. It tests only a domain and mailbox for which you have written authority.

Before you start

Time: 45–75 minutes
Difficulty: Intermediate
Lab environment: Ubuntu 26.04.1 LTS; BIND dig 9.20.24; OpenSSL 3.5.5. swaks is required for the final test; use the package version provided by your approved repository and record it in your lab notes.

You need:

  • written permission for example.com or another domain you administer;
  • a test recipient mailbox you can inspect;
  • the hostname and port of an SMTP submission service you are authorised to use;
  • a DKIM selector supplied by your mail provider or DNS zone;
  • no production credentials on the command line or in shell history.

Use the documentation-only names below until you substitute your own authorised values:

export DOMAIN=example.com
export SELECTOR=selector1
export SMTP_HOST=mail.example.com
export TEST_TO=mailbox@example.net

Do not scan arbitrary mail hosts, relay through a service you do not administer, or use this lab to test whether third parties will accept spoofed mail.

DNS lookups and a TLS handshake are low-impact observations, but they still generate logs. The swaks step sends a real message, so agree the sender, recipient, subject and maintenance window first. Send only to the approved mailbox. If you see an unexpected MX host, certificate name or authentication result, stop; preserve the output and check the domain’s intended architecture before changing DNS or mail configuration.

Checkpoint 1: map the delivery path

Step 1 — query MX records

Run:

dig +noall +answer MX "$DOMAIN"

Expected shape:

example.com. 300 IN MX 10 mx1.example.net.
example.com. 300 IN MX 20 mx2.example.net.

Interpretation: MX records identify the advertised inbound mail exchangers and their preference. They do not prove the hosts accept mail, that they are patched, or that every third-party sender uses them. A result with no MX may still be valid when the domain intentionally receives mail at its A/AAAA address, but treat it as a design decision to verify—not an automatic failure.

Record the answer, TTL and retrieval time. Compare it with the provider’s documented inbound hosts.

Step 2 — retrieve the SPF record

Run:

dig +short TXT "$DOMAIN" | tr -d '"'

Look for exactly one record beginning v=spf1, for example:

v=spf1 include:_spf.example.net -all

Good result: one syntactically plausible SPF policy that matches the services allowed to send mail for the domain.
Bad result: two separate v=spf1 records, which produces a permanent SPF error for evaluators.
Unclear result: an include: chain. It may be correct, but evaluate it with the provider’s tooling and account for SPF’s DNS-lookup limit; dig alone cannot prove policy evaluation.

SPF authenticates an SMTP envelope identity and an IP authorisation path. It does not encrypt mail, prove a visible From address, or stop a compromised authorised sender.

Checkpoint 2: inspect DKIM and DMARC

Step 3 — query the known DKIM selector

DKIM records live at selector._domainkey. With a selector from your provider:

dig +short TXT "$SELECTOR._domainkey.$DOMAIN" | tr -d '"'

Expected shape:

v=DKIM1; k=rsa; p=MIIBIjANBgkq...

Good result: the selector resolves and contains a public key or the provider’s documented indirection.
Bad result: NXDOMAIN for a selector that should be active, an empty p=, or a record copied from another tenant.
Unclear result: a selector can exist without any current message being signed by it. The message header test later is the evidence for signing and alignment.

Do not paste private DKIM keys into a terminal, ticket or article. Rotation normally means publishing a new selector, configuring signing with it, verifying mail, then retiring the old selector after the provider’s documented overlap period.

Step 4 — query DMARC

Run:

dig +short TXT "_dmarc.$DOMAIN" | tr -d '"'

Example:

v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com; adkim=s; aspf=s

Interpretation: p=none asks receivers to monitor; quarantine requests suspicious handling; reject requests rejection. A stricter policy is not automatically safer if legitimate senders are not aligned. DMARC requires alignment between the visible From domain and SPF or DKIM identity. The rua address receives aggregate reports; protect it because reports disclose mail-flow information.

A visible DMARC record does not prove every receiver enforces it, that reports are being collected, or that all authorised services are aligned.

Checkpoint 3: inspect STARTTLS without sending mail

Use the authorised submission or MX service. For STARTTLS on SMTP port 25:

openssl s_client -starttls smtp -connect "$SMTP_HOST:25" -servername "$SMTP_HOST" -verify_return_error </dev/null

For a submission service using implicit TLS, use port 465 and omit -starttls smtp:

openssl s_client -connect "$SMTP_HOST:465" -servername "$SMTP_HOST" -verify_return_error </dev/null

Expected indicators include Verification: OK, a certificate subject/SAN covering the hostname, and a negotiated TLS protocol and cipher. Save the non-sensitive summary:

openssl s_client -starttls smtp -connect "$SMTP_HOST:25" -servername "$SMTP_HOST"   -verify_return_error </dev/null 2>&1 |   grep -E 'Verification:|Protocol *:|Cipher *:|subject=|issuer='

A successful handshake proves that this client trusted the certificate chain for the name used. It does not prove all inbound peers use TLS, that DANE/MTA-STS is configured, or that a recipient’s provider will accept your mail.

If certificate verification fails, do not bypass it with -verify 0 in production. Check hostname, chain, time, the intended endpoint and provider documentation. Roll back by removing no configuration: this step is observational.

Checkpoint 4: send one controlled message

Install swaks from your approved repository, then check its installed version:

swaks --version

Use your authenticated submission service and a credential mechanism approved by the provider. Avoid putting passwords in a command argument. One controlled example is:

read -rsp "SMTP password: " SMTP_PASSWORD; echo
swaks --server "$SMTP_HOST" --port 587 --tls   --auth LOGIN --auth-user "test-sender@$DOMAIN" --auth-password "$SMTP_PASSWORD"   --from "test-sender@$DOMAIN" --to "$TEST_TO"   --header "Subject: authorised mail-authentication lab $(date -u +%F)"   --body "Authorised test message. Inspect Authentication-Results and received headers."
unset SMTP_PASSWORD

Expected SMTP result: a successful final 250 response from the authorised submission service. That proves this submission attempt was accepted by that service; it does not prove final delivery, inbox placement or DMARC enforcement at every recipient.

If the provider supports OAuth or an app password, prefer it over a primary mailbox password. If the test unexpectedly reaches an external recipient, stop future tests and review the recipient variable, transport logs and approval scope.

Checkpoint 5: read the received headers

Open the approved test mailbox and view the original message headers. Find Authentication-Results:. A healthy example may include:

spf=pass smtp.mailfrom=test-sender@example.com
dkim=pass header.d=example.com header.s=selector1
dmarc=pass header.from=example.com

Interpret each independently:

  • SPF pass means the evaluating receiver accepted the envelope sender and source relationship it saw.
  • DKIM pass means the signature validated for the shown domain and selector at that receiver.
  • DMARC pass means the receiver found aligned SPF or DKIM for the visible From domain.
  • No result or failure is an investigation lead, not proof that DNS is wrong. Forwarding, mailing lists, provider rewriting and the actual From/envelope identities matter.

Capture the message ID, UTC timestamp, redacted headers and result. Do not archive credentials, full recipient lists or unrelated message content.

Troubleshooting and containment

Symptom Safe next action Do not do
No DKIM answer Confirm selector with the signing provider and query the exact name Guess selectors across unrelated domains
SPF permerror Look for multiple SPF records or excessive indirection; change DNS only under change control Add a second v=spf1 record
Certificate name mismatch Stop, verify the documented submission hostname and preserve output Suppress verification permanently
DMARC fails Compare visible From, envelope sender and header.d; check each approved sender Raise policy from none to reject during the incident
Test message absent Check the approved mailbox’s junk folder and provider logs using message ID Repeatedly resend to unapproved addresses

There is no configuration change to roll back in the observation steps. If you changed a DNS record while diagnosing, restore the prior version from the approved change record, wait for the recorded TTL, then repeat only the affected checkpoint. If a credential was exposed in shell history or output, revoke or rotate it according to the provider’s procedure before continuing.

What this lab proves—and what it does not

This lab produces a time-stamped, limited evidence set for one domain, one selector, one endpoint and one test message. It cannot certify overall mail security or deliverability. Repeat it after provider migrations, DKIM key rotation, DMARC policy changes, and at least every 6–12 months. Link the results to the related domain/DNS hardening work and the business-email-compromise response process.

Clean-up

  1. Delete temporary terminal output containing addresses or headers from shared locations.
  2. Confirm SMTP_PASSWORD is unset and close the shell.
  3. Retain only the approved evidence: commands, UTC time, DNS answers, TLS summary, message ID and redacted authentication results.
  4. Record any exception, owner and review date.

Further exercises

  • Compare an aligned and deliberately non-aligned authorised test identity in a disposable lab domain.
  • Review a week of DMARC aggregate reports with the domain owner before changing policy.
  • Document every legitimate third-party sender, its SPF/DKIM method, owner and offboarding path.

Changes log

  • 2026-10-22 — Initial lab draft. Environment recorded: Ubuntu 26.04.1 LTS, BIND dig 9.20.24 and OpenSSL 3.5.5. Swaks must be version-recorded locally before execution.

References

  1. RFC 7489: Domain-based Message Authentication, Reporting, and Conformance (DMARC)
  2. RFC 7208: Sender Policy Framework (SPF)
  3. RFC 6376: DomainKeys Identified Mail (DKIM)
  4. OpenSSL s_client documentation
  5. Swaks official project documentation