Posted on 2009-08-14 12:04:36-07 by jaslong in response to 11248
Re: signing multipart alternative messages

Probably your best bet is to use MIME::Lite to construct the message, then express the entire message as a string. Once it is in string form, you can have Mail::DKIM create a signature for it. Concatenate the signature and the original message, then send it using something other than MIME::Lite.

If you really want to use MIME::Lite to send the message, perhaps something like this will work...

# $msg is the MIME::Lite object ### Prepare the Mail::DKIM object use Mail::DKIM::Signer; my $dkim = Mail::DKIM::Signer->new( Algorithm => "rsa-sha1", Method => "relaxed", Domain => "myhost.com", Selector => "mx1", KeyFile => "./private.key", ); # Mail::DKIM wants the message in the form it is transmitted, i.e. CR-LF line endings my $raw_data = $msg->as_string; $raw_data =~ s/\n/\015\012/gs; $dkim->PRINT($raw_data); $dkim->CLOSE; # Now create the signature my $sig = $dkim->signature; my ($header_name, $header_content) = split /:\s*/, $sig->as_string, 2; # Insert the signature at the beginning of the message (uses an undocumented API of MIME::Lite) unshift @{$msg->{Header}}, [ $header_name, $header_content ]; # Now send the message $msg->send();
Direct Responses: 12718 | 11321 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.