mediawiki本地發不出mail的解決辦法

來源:互聯網
上載者:User

 

MediaWiki有email通知功能以方便使用者註冊、重設密碼、修改通知等。但是但我開啟email功能之後,卻怎麼都發不出郵件,LocalSettings.php的相關配置如下:


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

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

$wgEmergencyContact = "abc@foo.com.cn";
$wgPasswordSender = "abc@foo.com.cn";
$wgNoReplyAddress       = 'abc@foo.com.cn';

$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 <apache@devsrv1.localdomain>: 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<apache@devsrv1.localdomain>
A<>
MDeferred: 450 4.1.8 <apache@devsrv1.localdomain>: Sender address rejected: Domain not found

rRFC822; abc@foo.com.cn
RPFD:<abc@foo.com.cn>
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 <abc@foo.com.cn>; 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: <200906160535.n5G5Z3vt004050@devsrv1.localdomain>
H??To: ABC <abc@foo.com.cn>
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: abc@foo.com.cn
.

 

從以上可以看出,問題出在郵件寄件者的網域名稱上,這些資訊具體是什麼用的,我不清楚。但從中我們可以看出由於網域名稱不對,發出的郵件被拒絕了。

 

上面用的是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 webmaster@example.com";

                        $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,其他版本應該也適用吧!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.