最近和几个朋友一起做用户态协议栈开源项目 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
|