What is Email Headers?

Email headers are lines of metadata at the beginning of an email message containing information about the sender, recipient, routing path, timestamps, and various processing instructions. Headers are crucial for email delivery, authentication, and debugging delivery issues.

Common Email Headers

Essential Headers

  • From: Sender's email address
  • To: Recipient's email address
  • Subject: Email subject line
  • Date: When the email was sent
  • Message-ID: Unique identifier for the email

Routing Headers

  • Received: Added by each server handling the email
  • Return-Path: Where bounces should be sent

Authentication Headers

  • DKIM-Signature: Digital signature for authentication
  • Authentication-Results: SPF/DKIM/DMARC check results

Custom Headers

  • X-*: Custom application headers
  • List-Unsubscribe: Unsubscribe URL for mailing lists

Testing Email Headers

When testing emails, headers help verify correct behavior:

test('email has correct headers', async () => {

await sendEmail({ to: testEmail, subject: 'Test Email', headers: { 'X-Campaign-ID': 'campaign-123', 'List-Unsubscribe': '<mailto:unsubscribe@example.com>', }, });

const email = await plop.getLatest(testEmail);

// Verify custom headers are present expect(email.headers['x-campaign-id']).toBe('campaign-123'); expect(email.headers['list-unsubscribe']).toBeDefined();

// Verify standard headers expect(email.headers['from']).toContain('@example.com'); expect(email.headers['message-id']).toBeDefined(); }); ```

Example

Parsing Email Headerstypescript
// Common header patterns to check in tests

// Verify unsubscribe header (required for marketing emails)
expect(email.headers['list-unsubscribe']).toMatch(
  /<mailto:|<https?:\/\//
);

// Check custom tracking headers
expect(email.headers['x-mailer']).toBe('MyApp/1.0');

// Verify reply-to is set correctly
expect(email.headers['reply-to']).toBe('support@example.com');

// Check content type for HTML emails
expect(email.headers['content-type']).toContain('multipart/alternative');

Try email headers with plop.email

Get started with reliable email testing in minutes.