mediawiki本地发不出mail的解决办法

 

MediaWiki有email通知功能以方便用户注册、重设密码、修改通知等。但是但我打开email功能之后,却怎么都发不出邮件,LocalSettings.php的相关配置如下:


## UPO means: this is also a user preference option

$wgEnableEmail      = true;
$wgEnableUserEmail  = false; # UPO

$wgEmergencyContact = "[email protected]";
$wgPasswordSender = "[email protected]";
$wgNoReplyAddress       = '[email protected]';

$wgEnotifUserTalk = false; # UPO
$wgEnotifWatchlist = false; # UPO
$wgEmailAuthentication = true;

 

希望能通过邮件重设某用户的密码,mediawiki默认是用PHP mail()发送邮件的,同样使用此函数的mantis就没有问题,所以基本可以排除我的系统配置的问题了。但是为什么mediawiki发出的邮件始终呆在mqueue里,不往外发呢?

 

/var/spool/mqueue/里对每个待发送邮件创建两个文件dfn***和qfn***,前者是邮件本身,后者是发送状态(可能是这样的,我没大研究,知道的告知一下,谢过先,呵呵)。

 

$cat /var/spool/mqueue/dfn5G5Z3gk004052


Someone, probably you, from IP address 192.168.1.150,
has registered an account "ABC" with this e-mail address on Mediawiki.

To confirm that this account really does belong to you and activate
e-mail features on Mediawiki, open this link in your browser:

http://devsrv1/wiki/index.php/Special:ConfirmEmail/686ba6f3aa68db10902f9699ed250b27

If you did *not* register the account, follow this link
to cancel the e-mail address confirmation:

http://devsrv1/wiki/index.php/Special:Invalidateemail/686ba6f3aa68db10902f9699ed250b27

This confirmation code will expire at 05:35, June 23, 2009.

 

$cat /var/spool/mqueue/qfn5G5Z3gk004052
V8
T1245130503
K1245143929
N5
P481061
I253/0/3424491
MDeferred: 450 4.1.8 <[email protected]>: Sender address rejected: Domain not found
Fbs
$_localhost.localdomain [127.0.0.1]
$rESMTP
$sdevsrv1.localdomain
${daemon_flags}
${if_addr}127.0.0.1
S<[email protected]>
A<>
MDeferred: 450 4.1.8 <[email protected]>: Sender address rejected: Domain not found
rRFC822; [email protected]
RPFD:<[email protected]>
H?P?Return-Path: <g>
H??Received: from devsrv1.localdomain (localhost.localdomain [127.0.0.1])
        by devsrv1.localdomain (8.14.2/8.14.2) with ESMTP id n5G5Z3gk004052
        for <[email protected]>; Tue, 16 Jun 2009 13:35:03 +0800
H?x?Full-Name: Apache
H??Received: (from apache@localhost)
        by devsrv1.localdomain (8.14.2/8.14.2/Submit) id n5G5Z3vt004050;
        Tue, 16 Jun 2009 05:35:03 GMT
H??Date: Tue, 16 Jun 2009 05:35:03 GMT
H??Message-Id: <[email protected]>
H??To: ABC <[email protected]>
H??Subject: Mediawiki e-mail address confirmation
H??MIME-Version: 1.0
H??Content-type: text/plain; charset=UTF-8
H??Content-Transfer-Encoding: 8bit
H??X-Mailer: MediaWiki mailer
H??From: [email protected]
.

 

从以上可以看出,问题出在邮件发送者的域名上,这些信息具体是什么用的,我不清楚。但从中我们可以看出由于域名不对,发出的邮件被拒绝了。

 

上面用的是mediawiki默认的apache@<$serverName>发送邮件,而且无法通过配置修改,无论你把$wgEmergencyContact, $wgPasswordSender, 和$wgNoReplyAddress改成什么都不管用。所以还要自己想解决办法。

 

我google的一些资料,有的人已经跟踪到上面的queue里发现的线索了,但是最好还是功亏一篑。联想到mantis和mediawiki都是用PHP mail()发送的邮件,一个成功一个失败,可能的情况就是mantis在使用该函数使用的某些参数mediawiki没有使用,所以这个问题应该可以想办法绕过的。

 

查看了一下mantis的源码,并到PHP官方网站上查了一下manual,发现PHP mail()确实可以给mail发送程序传送某种参数,而这里使用的是参数-f。

 

于是修改的一下mediawiki的邮件发送程序include/UserMailer.php,问题解决。至少发送邮件没有问题了:)

 

                        $wgErrorString = '';
                        $html_errors = ini_get( 'html_errors' );
                        ini_set( 'html_errors', '0' );
                        set_error_handler( array( 'UserMailer', 'errorHandler' ) );
                        wfDebug( "Sending mail via internal mail() function/n" );

                        if (function_exists('mail')) {
                                if (is_array($to)) {
                                        foreach ($to as $recip) {
                                                $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers );
                                        }
                                } else {
                                        $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, );
                                }
                        } else {
                                $wgErrorString = 'PHP is not configured to send mail';
                        }

 

改为

 


                        $params = "-oi -f [email protected]";

                        $wgErrorString = '';
                        $html_errors = ini_get( 'html_errors' );
                        ini_set( 'html_errors', '0' );
                        set_error_handler( array( 'UserMailer', 'errorHandler' ) );
                        wfDebug( "Sending mail via internal mail() function/n" );

                        if (function_exists('mail')) {
                                if (is_array($to)) {
                                        foreach ($to as $recip) {
                                                $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $params );
                                        }
                                } else {
                                        $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, $params );
                                }
                        } else {
                                $wgErrorString = 'PHP is not configured to send mail';
                        }

PS: 我用的mediawiki是1.14.x,其他版本应该也适用吧!

 

你可能感兴趣的:(apache,html,PHP,function,ini,domain)