Mail::DMARC(3pm)

✨ Mail::DMARC ✨

okay so bestie, you know how the manpage header says Mail::DMARC(3pm) up top and it's filed under User Contributed Perl Documentation? that's literally this whole page. the module is Mail::DMARC β€” Perl implementation of DMARC. slay. πŸ’…

also there's a "Status Badges" thing chilling right at the top of the original, so like. consider it noted. πŸŽ€


πŸ’– NAME πŸ’–

Mail::DMARC β€” Perl implementation of DMARC. that's it. that's the name. iconic.

🌸 VERSION 🌸

version 1.20260306

πŸ¦‹ SYNOPSIS πŸ¦‹

DMARC: Domain-based Message Authentication, Reporting and Conformance. say it with your chest. πŸ‘‘

  my $dmarc = Mail::DMARC::PurePerl->new(
    ... # see the documentation for the "new" method for required args
  );

  my $result = $dmarc->validate();

  if ( $result->result eq 'pass' ) {
     ...continue normal processing...
     return;
  };

  # any result that did not pass is a fail. Now for disposition

  if ( $result->disposition eq 'reject' ) {
     ...treat the sender to a 550 ...
  };
  if ( $result->disposition eq 'quarantine' ) {
     ...assign a bunch of spam points...
  };
  if ( $result->disposition eq 'none' ) {
     ...continue normal processing...
  };

like, that's the whole vibe. validate, then do whatever the disposition tells you. no cap. πŸ”₯

🧚 DESCRIPTION 🧚

This module is lowkey a whole suite of tools for implementing DMARC. It adheres to the 2013 DMARC draft, and it's out here intending to implement every MUST and every SHOULD. overachiever behavior, honestly. we love to see it. πŸ’œ

This module can be used by...

  • MTAs and filtering tools like SpamAssassin, to validate that incoming messages are aligned with the purported sender's policy. πŸ•΅οΈβ€β™€οΈ
  • email senders, to receive DMARC reports from other mail servers and display them via CLI and web interfaces. πŸ“¬
  • MTA operators, to send DMARC reports to DMARC author domains. πŸ“€

So when a message arrives via SMTP, the MTA or filtering application can pass in a small amount of metadata about the connection (envelope details, SPF and DKIM results) to Mail::DMARC. Then when the validate method is called, Mail::DMARC will determine if:

a. the header_from domain exists b. the header_from domain publishes a DMARC policy c. if a policy is published... d. does the message conform to the published policy? e. did the policy request reporting? If so, save details.

The validation results are returned as a Mail::DMARC::Result object. If the author domain requested a report, it was saved to the Report Store. The Store class includes a SQL implementation that is tested with SQLite, MySQL and PostgreSQL. multi-database queen. πŸ‘‘

There is more information available in the $result object. See Mail::DMARC::Result for complete details.

Reports are viewed with the dmarc_view_reports program, or with a web browser and the dmarc_httpd program. πŸ–₯️

Aggregate reports are sent to their requestors with the dmarc_send_reports program.

For aggregate reports that you have been sent, the dmarc_receive program will parse the email messages (from IMAP, Mbox, or files) and save the report results into the Report Store. πŸ“₯

The report store can use the same database to store reports you have received as well as reports you will send. There are several ways to identify the difference, including:

  • received reports will have a null value for report_policy_published.rua
  • outgoing reports will have null values for report.uuid and report_record.count

🌈 CLASSES 🌈

  • Mail::DMARC β€” the perl interface for DMARC
  • Mail::DMARC::Policy β€” a DMARC policy
  • Mail::DMARC::PurePerl β€” Pure Perl implementation of DMARC
  • Mail::DMARC::Result β€” the results of applying policy
  • Mail::DMARC::Report β€” Reporting: the R in DMARC
    • Mail::DMARC::Report::Send β€” send reports via SMTP & HTTP
    • Mail::DMARC::Report::Receive β€” receive and store reports from email, HTTP
    • Mail::DMARC::Report::Store β€” a persistent data store for aggregate reports
    • Mail::DMARC::Report::View β€” CLI and CGI methods for viewing reports
  • Mail::DMARC::libopendmarc <http://search.cpan.org/~shari/Mail-DMARC-opendmarc> β€” an XS implementation using libopendmarc

it's giving family tree. 🌳


πŸŽ€ METHODS πŸŽ€

new

Create a DMARC object. baby's first DMARC. 🍼

    my $dmarc = Mail::DMARC::PurePerl->new;

Populate it. ✨

    $dmarc->source_ip('192.0.1.1');
    $dmarc->envelope_to('recipient.example.com');
    $dmarc->envelope_from('sender.example.com');
    $dmarc->header_from('sender.example.com');
    $dmarc->dkim( $dkim_verifier );
    $dmarc->spf([
        {   domain => 'example.com',
            scope  => 'mfrom',
            result => 'pass',
        },
        {
            scope  => 'helo',
            domain => 'mta.example.com',
            result => 'fail',
        },
    ]);

Run the request:

    my $result = $dmarc->validate();

Alternatively, pass in all the required parameters in one shot β€” efficiency era:

    my $dmarc = Mail::DMARC::PurePerl->new(
            source_ip     => '192.0.1.1',
            envelope_to   => 'example.com',
            envelope_from => 'cars4you.info',
            header_from   => 'yahoo.com',
            dkim          => $dkim_results,  # same format
            spf           => $spf_results,   # as previous example
            );
    my $result = $dmarc->validate();

source_ip

The remote IP that attempted sending the message. DMARC only uses this data for reporting to domains that request DMARC reports. so like, it's not being nosy, it's just doing its job. πŸ’…

envelope_to

The domain portion of the RFC5321.RcptTo (aka, the envelope recipient), and the bold portion in the following example:

        RCPT TO:<user@example.com>

envelope_from

The domain portion of the RFC5321.MailFrom (aka, the envelope sender). That is the the bold portion in the following example:

        MAIL FROM:<user@example.com>

(yes, the original says "the the". we're keeping it. it's canon now. 😭)

header_from

The domain portion of the RFC5322.From, aka, the From message header. 🏷️

        From: Ultimate Vacation <sweepstakes@example.com>

You can instead pass in the entire From: header with header_from_raw.

header_from_raw

Retrieve the header_from domain by parsing it from a raw From field/header. The domain portion is extracted by get_dom_from_header, which is fast, generally effective, but also rather crude. It has limits, so read the description. ngl, "fast and crude" is a whole personality. πŸ™ˆ

dkim

If Mail::DKIM::Verifier was used to validate the message, just pass in the Mail::DKIM::Verifier object that processed the message:

    $dmarc->dkim( $dkim_verifier );

Otherwise, pass in an array reference. Each member of the DKIM array results represents a DKIM signature in the message and consists of the 4 keys shown in this example:

    $dmarc->dkim( [
            {
                domain      => 'example.com',
                selector    => 'apr2013',
                result      => 'fail',
                human_result=> 'fail (body has been altered)',
            },
            {
                # 2nd signature, if present
            },
        ] );

The dkim results can also be build iteratively by passing in key value pairs or hash references for each signature in the message:

    $dmarc->dkim( domain => 'sig1.com', result => 'fail' );
    $dmarc->dkim( domain => 'sig2.com', result => 'pass' );
    $dmarc->dkim( { domain => 'example.com', result => 'neutral' } );

Each hash or hashref is appended to the dkim array. πŸ“š

Finally, you can pass a coderef which won't be called until the dkim method is used to read the dkim results. It must return an array reference as described above. lazy-loading king. 🫢

The dkim result is an array reference.

domain

The d= parameter in the DKIM signature.

selector

The s= parameter in the DKIM signature.

result

The validation results of this signature. One of: none, pass, fail, policy, neutral, temperror, or permerror.

human result

Additional information about the DKIM result. This is comparable to Mail::DKIM::Verifier->result_detail.

spf

The spf method works exactly the same as dkim. It accepts named arguments, a hashref, an arrayref, or a coderef:

    $dmarc->spf(
        domain => 'example.com',
        scope  => 'mfrom',
        result => 'pass',
    );

The SPF domain and result are required for DMARC validation, and the scope is used for reporting.

domain

The SPF checked domain.

scope

The scope of the checked domain: mfrom, helo.

result

The SPF result code: none, neutral, pass, fail, softfail, temperror, or permerror.


πŸ”₯ DESIGN & GOALS πŸ”₯

Correct

The DMARC spec is lengthy and evolving, making correctness a moving target. In cases where correctness is ambiguous, options are generally provided. it's giving "we don't know either, so here's a knob for it". πŸŽ›οΈ

Easy to use

Providing an implementation of DMARC that SMTP utilities can utilize will aid DMARC adoption.

The list of dependencies appears long because of reporting. If this module is used without reporting, the number of dependencies not included with perl is about 5. five. that's it. humble. 🌱

Maintainable

Since DMARC is evolving, this implementation aims to be straight forward and easy to alter and extend. The programming style is primarily OO, which carries a small performance penalty but dividends in maintainability. girl math: lose a little speed, gain a whole personality. πŸ’β€β™€οΈ

When multiple options are available, such as when sending reports via SMTP or HTTP, calls should be made to the parent Send class to broker the request. When storing reports, calls are made to the Store class which dispatches to the SQL class. The idea is that if someone desired a data store other than those provided by perl's DBI class, they could easily implement their own. If you do, please fork it on GitHub and share. 🍴 bestie please. we beg.

Fast

If you deploy this in an environment where performance is insufficient, please profile the app and submit a report and preferably, patches. profile first, then complain. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

go read. for me. 🫢


🌸 HISTORY 🌸

The daddy of this perl module was a DMARC module for the qpsmtpd MTA <https://github.com/smtpd/qpsmtpd/blob/master/plugins/dmarc>. ancestral icon. 🧬


πŸ’– AUTHORS πŸ’–

  • Matt Simerson <msimerson@cpan.org>
  • Davide Migliavacca <shari@cpan.org>
  • Marc Bradshaw <marc@marcbradshaw.net>

🌈 CONTRIBUTORS 🌈

  • Benny Pedersen <me@junc.eu>
  • Jean Paul Galea <jeanpaul@yubico.com>
  • Marisa Clardy <marisa@clardy.eu>
  • Priyadi Iman Nurcahyo <priyadi@priyadi.net>
  • Ricardo Signes <rjbs@cpan.org>

legends, all of them. 🫑


This software is copyright (c) 2026 by Matt Simerson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in go off. πŸ’œ


okay that's the whole page!! sending you off with a cute little sign-off: this was rendered by perl v5.40.1 on 2026-07-07, and the page itself is Mail::DMARC(3pm). mwah. πŸ“βœ¨πŸ’…
πŸ“¦ where this page comes from