使用Bugzilla,你肯定会遇到的坑。

在搭建Bugzilla用于管理NtyTcp项目中遇到的Bug时,发现由于阿里云封禁25端口,SMTP无法发送邮件。通过研究Bugzilla源码并自学Perl,解决了465端口邮件发送问题,最终成功实现邮件通知功能。文章分享了修复过程及Perl邮件发送代码示例。
摘要由CSDN通过智能技术生成

最近和几个朋友一起做用户态协议栈开源项目 NtyTcp ,纯业余爱好,个人情怀。刚刚开始做有好多的Bug,故搭建了一个Bugzilla,用来上传Bug的。

有几个开发朋友想在 bug.ntytcp.com提交bug,不能注册,因为不能发邮件。至于为什么不能发送邮件?因为阿里云把25端口封了,使用smtp不能发送。

使用465端口发送,发现发不出来,又找不到原因。硬着头皮比Bugzilla的源码看了一下。可恨的是自己并没有写过perl代码。


于是用了两天时间连学带看就把bugzilla的源码看了一遍。然后把bugzilla邮件发送的部分重写了一下。先把bugzilla邮件发送部分贴出来。

bugzilla/mailer.pm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
sub  MessageToMTA {
my  ( $msg $send_now ) = ( @_ );
my  $method  = Bugzilla->params->{ 'mail_delivery_method' };
return  if  $method  eq  'None' ;
 
if  (Bugzilla->params->{ 'use_mailer_queue' }
&& !  $send_now
&& ! Bugzilla->dbh->bz_in_transaction()
) {
Bugzilla->job_queue->insert( 'send_mail' , { msg =>  $msg  });
return ;
}
 
my  $dbh  = Bugzilla->dbh;
 
my  $email  ref ( $msg ) ?  $msg  : Bugzilla::MIME->new( $msg );
 
# If we're called from within a transaction, we don't want to send the
# email immediately, in case the transaction is rolled back. Instead we
# insert it into the mail_staging table, and bz_commit_transaction calls
# send_staged_mail() after the transaction is committed.
if  (!  $send_now  &&  $dbh ->bz_in_transaction()) {
# The e-mail string may contain tainted values.
my  $string  $email ->as_string;
trick_taint( $string );
 
my  $sth  $dbh ->prepare( "INSERT INTO mail_staging (message) VALUES (?)" );
$sth ->bind_param(1,  $string $dbh ->BLOB_TYPE);
$sth ->execute;
return ;
}
 
my  $from  $email ->header( 'From' );
 
my  $hostname ;
my  $transport ;
if  ( $method  eq  "Sendmail" ) {
if  (ON_WINDOWS) {
$transport  = Bugzilla::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE });
}
else  {
$transport  = Bugzilla::Sender::Transport::Sendmail->new();
}
}
else  {
# Sendmail will automatically append our hostname to the From
# address, but other mailers won't.
my  $urlbase  = Bugzilla->params->{ 'urlbase' };
$urlbase  =~ m|//([^:/]+)[:/]?|;
$hostname  = $1 ||  'localhost' ;
$from  .=  "\@$hostname"  if  $from  !~ /@/;
$email ->header_set( 'From' $from );
# Sendmail adds a Date: header also, but others may not.
if  (! defined  $email ->header( 'Date' )) {
$email ->header_set( 'Date' , time2str( "%a, %d %b %Y %T %z" time ()));
}
}
 
if  ( $method  eq  "SMTP" ) {
my  ( $host $port ) =  split (/:/, Bugzilla->params->{ 'smtpserver' }, 2);
$transport  = Bugzilla->request_cache->{smtp} //=
Email::Sender::Transport::SMTP::Persistent->new({
host  =>  $host ,
defined
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值