解决mantis无法发送邮件的问题
解决mantis无法发送邮件的问题
http://www.pooy.net/mantis-send-email.html
Mantis安装好之后,注册用户的时候,发送用户邮件不太好使。通过查看Mantis源码,调试mantis邮件配置后解决了这个的问题。
1,测试发送邮件
需要修改的文件:config_defaults_inc.php。下面以腾讯企业邮箱为例
|
001
002
003
004
005
006
007
008
009
010
|
$g_administrator_email = 'mantis@pooy.net';$g_webmaster_email = 'mantis@pooy.net';$g_from_email = 'mantis@pooy.net';$g_return_path_email = 'mantis@pooy.net';$g_enable_email_notification = ON;$g_phpMailer_method = PHPMAILER_METHOD_SMTP;$g_smtp_host = 'smtp.exmail.qq.com';$g_smtp_username = 'mantis@pooy.net';$g_smtp_password = 'JD8WJ9KD';$g_smtp_port = 465; |
配置文件修改完毕之后,接着开始测试:mantis里面自带有测试文件,目录在:library/phpmailer/email.php
我的测试脚本如下:
|
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
|
<?php/** * @author [pooy] <[pooy@pooy.net]> * @blog http://www.pooy.net */require 'class.phpmailer.php';$mail = new PHPMailer;$mail->SMTPDebug = 1;$mail->IsSMTP(); // Set mailer to use SMTP$mail->Host = 'smtp.exmail.qq.com'; // Specify main and backup server$mail->SMTPAuth = true; // Enable SMTP authentication$mail->Username = 'mantis@pooy.net'; // SMTP username$mail->Port = 465;$mail->Password = 'JD8WJ9KD'; // SMTP password$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted$mail->From = 'mantis@pooy.net';$mail->FromName = 'Mailer Testing';$mail->WordWrap = 50; // Set word wrap to 50 characters$mail->IsHTML(true); // Set email format to HTML$mail->Subject = 'Here is the subject';$mail->Body = 'This is the HTML message body <b>in bold!</b>';$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit;}echo 'Message has been sent';// To load the French version$mail->SetLanguage('cn', '/optional/path/to/language/directory/');?> |
你可以使用浏览器访问这个脚本,或者直接在shell或者dos下运行这个。
因为上面我开了debug,所以会得到下面的返回结果:
|
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
|
CLIENT -> SMTP: EHLO 115.28.15.50CLIENT -> SMTP: AUTH LOGINCLIENT -> SMTP: bWFudGlzQHdlaXRvdWh1aXJvbmcuY29tCLIENT -> SMTP: SkQ4V0o5S0Q=CLIENT -> SMTP: MAIL FROM:CLIENT -> SMTP: RCPT TO:CLIENT -> SMTP: DATACLIENT -> SMTP: Date: Wed, 7 May 2014 16:34:36 +0800CLIENT -> SMTP: Return-Path:CLIENT -> SMTP: To: PooyCLIENT -> SMTP: From: Mailer TestingCLIENT -> SMTP: Subject: Here is the subjectCLIENT -> SMTP: Message-ID:CLIENT -> SMTP: X-Priority: 3CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)CLIENT -> SMTP: MIME-Version: 1.0CLIENT -> SMTP: Content-Type: multipart/alternative;CLIENT -> SMTP: boundary="b1_d5e58d84c060fd873a3452afc752ca93"CLIENT -> SMTP:CLIENT -> SMTP: --b1_d5e58d84c060fd873a3452afc752ca93CLIENT -> SMTP: Content-Type: text/plain; charset=iso-8859-1CLIENT -> SMTP: Content-Transfer-Encoding: 8bitCLIENT -> SMTP:CLIENT -> SMTP: This is the body in plain text for non-HTML mailCLIENT -> SMTP: clientsCLIENT -> SMTP:CLIENT -> SMTP:CLIENT -> SMTP: --b1_d5e58d84c060fd873a3452afc752ca93CLIENT -> SMTP: Content-Type: text/html; charset=iso-8859-1CLIENT -> SMTP: Content-Transfer-Encoding: 8bitCLIENT -> SMTP:CLIENT -> SMTP: This is the HTML message body in bold!CLIENT -> SMTP:CLIENT -> SMTP:CLIENT -> SMTP:CLIENT -> SMTP: --b1_d5e58d84c060fd873a3452afc752ca93--CLIENT -> SMTP:CLIENT -> SMTP: .CLIENT -> SMTP: quitMessage has been sent |
到这里,说明测试邮件发送无误!
2,注册发送邮件
用SMTP发送邮件时,发送进程比较慢,如果参数g_email_send_using_cronjob设置为OFF,则MantisBT的处理脚本就要 等待邮件发送进程结束才会返回,这样用户往往要等待很久才能看到页面的反馈,用户体验很差。当上述参数设置为ON时,MantisBT会将待发送通知邮件 放入邮件队列,等待定时进程发送。
定时脚本在:
|
001
|
php /home/yourusername/yourpath/mantis/scripts/send_emails.php |
可以放在crontab里面一分钟执行一次
#Mantis Sending emailList
|
001
|
*/1 * * * * php /data/www/mantis/scripts/send_emails.php >/dev/null |
调试的时候,第一次可能会出现:
|
001
002
003
004
|
sh: /var/qmail/bin/sendmail: No such file or directorysh: /var/qmail/bin/sendmail: No such file or directorySending emails...Done. |
原因是因为config_defaults_inc.php文件中的:
|
001
|
$g_phpMailer_method =PHPMAILER_METHOD_SENDMAIL; |
在一开始我提过要修改成:
|
001
|
$g_phpMailer_method = PHPMAILER_METHOD_SMTP; |
那样就可以使用class.phpmailer.php了。
最后还需要修改emil_api.php中的 email_send 函数中的:
|
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
|
if( is_null( $g_phpMailer ) ) { if ( $t_mailer_method == PHPMAILER_METHOD_SMTP ) { register_shutdown_function( 'email_smtp_close' ); } $mail = new PHPMailer(true); /** * 添加发送邮件的参数 * @author [pooy] <[pooy@pooy.net]> */ $mail->SMTPDebug = 1; //生产环境中去掉 $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Port = 465; $mail->SMTPSecure = 'ssl'; } else { $mail = $g_phpMailer; } |
到这里,就可以自动完成定时发送邮件的服务了。这里顺便说一下mantis发送邮件的原理:定时任务中的send_emails.php,会读取数据库的邮件队列表mantis_email_table.获取发送的列表后,依次按照ID的升序发送,发送完毕后清空。等待下次队列,周而复始。
关键字:mantis邮件设置,mantis邮件提醒,mantis邮件发送,mantis发邮件,mantis无法发送邮件

浙公网安备 33010602011771号