DKIM signing in perl

MT Hosting
#[email protected]
#Simple DKIM
#V0.1

use Mail::DKIM::Signer;
use Email::Simple;

@ARGV == 1 or die "Missing File Name";

$domain = "mysecureservice.com";
$key = "C:\\Ahsay\\CustomScripts\\$domain.priv";
$dkimsel = "dkim";
$dksel = "dk";
my $dkim = Mail::DKIM::Signer->new(
Algorithm => "rsa-sha1",
Method => "relaxed", 
Domain => $domain, 
Selector => $dkimsel, 
KeyFile => $key);

open(mail,"< $ARGV[0]");
$emailm = "";

while ()
{
chomp;
s/\015$//;
$dkim->PRINT("$_\015\012");
$emailm = "$emailm"."$_\n";
}
$dkim->CLOSE;
close mail;

my $email = Email::Simple->new($emailm);
$dkimsig = $dkim->signature->as_string();
$dkimsig =~ s/DKIM-Signature: //;

$email->header_set("DKIM-Signature", $dkimsig);


open (mail, "> $ARGV[0]");
$emailmsg = $email->as_string;
#$emailmsg =~ s/\015$//;
print mail $emailmsg;
close mail;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.