Thanks for the upload! Here's the version I had put together in the meantime, which seems
to work (probably because it uses &field_order, which ensures the DKIM header stays on top).
However, patching MIME::Lite directly to support this header (and not lowercase it btw) is
probably a better option.
#!/usr/bin/env perl
use strict;
use warnings;
use MIME::Lite;
use IO::File;
use Mail::DKIM::Signer;
my $msg = MIME::Lite->new(
From => 'sender@domain.tld',
To => 'recipient@other.tld',
Subject => 'Test de message (DKIM)',
Data => "Doses this work at all?"
);
my $fh = IO::File->new_tmpfile;
$msg->print($fh);
$fh->seek( 0, 0 );
my $dkim = Mail::DKIM::Signer->new(
Algorithm => "rsa-sha1",
Method => "relaxed",
Domain => "my.domain.com",
Selector => "key1",
KeyFile => "my-domain.dkim.priv.key",
);
$dkim->load($fh);
my $signature = $dkim->signature;
($signature = $dkim->signature->as_string) =~ s/^DKIM-Signature: //;
$fh->close;
# Header is lowercased by M:Lite, could be an issue
$msg->field_order( 'Dkim-Signature' );
$msg->add('Dkim-Signature' => $signature );
print $msg->as_string;
$msg->send_by_smtp('my.smtp.com');