Perl DKIM签名:缺少签名的头字段属性值

时间:2017-09-11 11:00:24

标签: perl email dkim

我尝试使用Mail::DKIM::Signer 添加带邮件的DKIM签名。粘贴下面的代码片段

 use Mail::Sendmail ();
 use Mail::DKIM::Signer;
 my $msg = <<"MESSAGE";
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
       <div style="width: 600px"><p style="font-family: \'arial\'; font-size: 13px; margin-bottom: 13px;">Sample mail content</p>
       </div>
    </body>
 </html>
 MESSAGE

 my %mail = (
      'to' => 'user@xxxxxx.com',
      'content-type' => 'text/html',
      'from' => 'registration@xxxxxx.com',
      'subject' => 'Registration Confirmation',
      'message' => $msg,
     )     
 my $dkim = Mail::DKIM::Signer->new(
              Algorithm => "rsa-sha1",
              Method => "relaxed",
              Domain => "example.org",
              Selector => "selector1",
              KeyFile => "private.key",
              Headers => "x-header:x-header2",
         );
 $dkim->load(*STDIN);
 while (<STDIN>)
   {
     chomp;
       s/\015$//;
     $dkim->PRINT("$_\015\012");
   }
 $dkim->CLOSE;
 print $dkim->signature->as_string;

 my $dkim_signature = $dkim->signature->as_string;
 $dkim_signature =~ s/DKIM-Signature:\s?//g;
 $mail{'DKIM-Signature'} = $dkim_signature;

 Mail::Sendmail::sendmail(%mail) or warn $Mail::Sendmail::error;

结果

DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=example.org; h=; s=dkim; bh=alj1siencyWfsTsFskjsl/HadEf; b=kjsvnojnlke5RjsdxL1InuXGjzp0LstlT0oI4ReqLUejsdxL1InuXGjzp0LstlT0oI4ReqLUoQzjryb5ap5V1vDU0prMGg2wN+5BhewRSb+caS9pNwSpuOsjR7g5YTwA3EsNXSRHMxVWHYOqYTwA3EsNHgRBxFdArtiWrhoF+cs=

签名h(已签名的标题字段列表)中没有任何导致DKIM失败的值。

0 个答案:

没有答案