bugzilla使用第三方SMTP发邮件及乱码问题解决

来源:互联网 发布:生日提醒软件农历 编辑:程序博客网 时间:2024/05/21 17:24

Bugzilla2.22下发邮件,不必要安装什么特殊的sendmail.exe软件之类,只需要修改Bugzilla/BugMail.pm文件

1.在文件头部(不是文件的最上部)加入对Base64包引用:

   use MIME::Base64;
2.修改MessageToMTA方法如下:

sub MessageToMTA {
    my ($msg) = (@_);
    return if (Param('mail_delivery_method') eq "none");
 
    my ($header, $body) = $msg =~ /(.*?/n)/n(.*)/s ? ($1, $2) : ('', $msg);
    my $headers;
 
    if (Param('utf8') and (!is_7bit_clean($header) or !is_7bit_clean($body))) {
        ($headers, $body) = encode_message($msg);
    } else {
        my @header_lines = split(//n/, $header);
        $headers = new Mail::Header /@header_lines, Modify => 0;
    }
 
     my   @header;
          push   @header,   'Content-Type:   text/plain;   charset="gb2312"'.   "/n";
          my   @new_msg;
                    {
                                    use   Encode;
                                    no   strict   'refs';
                                    push   @new_msg,   encode("euc-cn",decode("utf8",$msg));
                    }
 
    my $from = trim($headers->get('from'));
    my $rcpt_to = trim($headers->get('to'));
 
    use Net::SMTP;
     my $smtp_server = 'mail.cvtt.cn';
     my $smtp_user = 'panglei@cvtt.cn';
     my $smtp_pass = 'passwd';
 
     my $encode_smtpuser = trim(encode_base64($smtp_user));
     my $encode_smtppass = trim(encode_base64($smtp_pass));
 
     my $smtp = Net::SMTP->new($smtp_server,Timeout => 60) ||
     die 'Cannot connect to smtp server';
 
     my $result = $smtp->command('AUTH','LOGIN');
     my $answer = $smtp->getline();
     # 334 VXNlcm5hbWU6
 
     $result = $smtp->command($encode_smtpuser);
     $answer = $smtp->getline();
     # 334 UGFzc3dvcmQ6
 
     $result = $smtp->command($encode_smtppass);
     $answer = $smtp->getline();
     # 235 Authentication successful
     # or 535 Authentication failed
     if ($answer =~ /535/i)
     {print "Sorry,Authentication failed!n";exit;}
 
     $smtp->mail($smtp_user);
     $smtp->to($rcpt_to);
     $smtp->data();
     $smtp->datasend($msg);
     $smtp->dataend();
     $smtp->quit;
 
}
3.对于Bugzilla发送中文邮件乱码问题的解决:

    (1)将/Bugzilla/CGI.pm中

         # Send appropriate charset
        $self->charset(Param('utf8') ? 'UTF-8' : ''); 

         改为:$self->charset('UTF-8');

    (2)在/Bugzilla/BugMail.pm第586行加上两行:

          use Encode;
          $substs{"summary"} = encode('MIME-Q', $substs{"summary"});

    (3)打开Bugzilla的网页,进入Bugzilla的系统设置(Parameters),在Email项的
          newchangedmail 中本框文字的第一行加上Content-type: text/plain; charset=UTF-8

设置之后如果邮件标题中还是乱码, 就打开系统设置(Parameters), 找到Email项的 newchangedmail:一项,将该项下文本框里面的 Subject: [Bug %bugid%] %summary% 改为 Subject: %neworchanged% [Bug %bugid%] 吧,总之避开 %summary% 这个变量里面的汉字