ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Web Security

Email Header Analysis

Parse raw email headers, trace sender path, and verify SPF, DKIM, and DMARC authentication results.

2 snippets Intermediate email-header-analyzer
email headersSPFDKIMDMARCReceivedspoofing

What you'll learn

  • Parse Received headers
  • Extract auth results

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

2 ready-to-use snippets for email header analysis. Click copy and paste into your project.

Parse Received headers
                function parseReceivedHeaders(rawHeaders) {
  const lines = rawHeaders.split('\n');
  const received = [];
  let current = '';
  for (const line of lines) {
    if (line.startsWith('Received:')) {
      if (current) received.push(current);
      current = line.slice(9).trim();
    } else if (/^\s/.test(line) && current) {
      current += ' ' + line.trim();
    }
  }
  if (current) received.push(current);
  return received; // newest first
}
              
Extract auth results
                function extractAuthResults(headers) {
  const authHeader = headers.find(h =>
    h.startsWith('Authentication-Results:')
  );
  if (!authHeader) return null;

  const results = { spf: null, dkim: null, dmarc: null };
  if (/spf=pass/i.test(authHeader)) results.spf = 'pass';
  if (/dkim=pass/i.test(authHeader)) results.dkim = 'pass';
  if (/dmarc=pass/i.test(authHeader)) results.dmarc = 'pass';
  return results;
}
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site