Mantis安装好之后,注册用户的时候,发送用户邮件不太好使。通过查看Mantis源码,调试mantis邮件配置后解决了这个的问题。

1,测试发送邮件
需要修改的文件:config_defaults_inc.php。下面以腾讯企业邮箱为例

     $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
我的测试脚本如下:

<?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,所以会得到下面的返回结果:

CLIENT -> SMTP: EHLO 115.28.15.50
CLIENT -> SMTP: AUTH LOGIN
CLIENT -> SMTP: bWFudGlzQHdlaXRvdWh1aXJvbmcuY29t
CLIENT -> SMTP: SkQ4V0o5S0Q=
CLIENT -> SMTP: MAIL FROM:
CLIENT -> SMTP: RCPT TO:
CLIENT -> SMTP: DATA
CLIENT -> SMTP: Date: Wed, 7 May 2014 16:34:36 +0800
CLIENT -> SMTP: Return-Path:
CLIENT -> SMTP: To: Pooy
CLIENT -> SMTP: From: Mailer Testing
CLIENT -> SMTP: Subject: Here is the subject
CLIENT -> SMTP: Message-ID:
CLIENT -> SMTP: X-Priority: 3
CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SMTP: MIME-Version: 1.0
CLIENT -> SMTP: Content-Type: multipart/alternative;
CLIENT -> SMTP: boundary="b1_d5e58d84c060fd873a3452afc752ca93"
CLIENT -> SMTP:
CLIENT -> SMTP: --b1_d5e58d84c060fd873a3452afc752ca93
CLIENT -> SMTP: Content-Type: text/plain; charset=iso-8859-1
CLIENT -> SMTP: Content-Transfer-Encoding: 8bit
CLIENT -> SMTP:
CLIENT -> SMTP: This is the body in plain text for non-HTML mail
CLIENT -> SMTP: clients
CLIENT -> SMTP:
CLIENT -> SMTP:
CLIENT -> SMTP: --b1_d5e58d84c060fd873a3452afc752ca93
CLIENT -> SMTP: Content-Type: text/html; charset=iso-8859-1
CLIENT -> SMTP: Content-Transfer-Encoding: 8bit
CLIENT -> 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: quit
Message has been sent

到这里,说明测试邮件发送无误!

2,注册发送邮件

用SMTP发送邮件时,发送进程比较慢,如果参数g_email_send_using_cronjob设置为OFF,则MantisBT的处理脚本就要 等待邮件发送进程结束才会返回,这样用户往往要等待很久才能看到页面的反馈,用户体验很差。当上述参数设置为ON时,MantisBT会将待发送通知邮件 放入邮件队列,等待定时进程发送。
定时脚本在:

php /home/yourusername/yourpath/mantis/scripts/send_emails.php

可以放在crontab里面一分钟执行一次
#Mantis  Sending  emailList

*/1 * * * *  php /data/www/mantis/scripts/send_emails.php  >/dev/null

调试的时候,第一次可能会出现:

sh: /var/qmail/bin/sendmail: No such file or directory
sh: /var/qmail/bin/sendmail: No such file or directory
Sending emails...
Done.

原因是因为config_defaults_inc.php文件中的:

$g_phpMailer_method          =PHPMAILER_METHOD_SENDMAIL;

在一开始我提过要修改成:

$g_phpMailer_method          = PHPMAILER_METHOD_SMTP;

那样就可以使用class.phpmailer.php了。
最后还需要修改emil_api.php中的 email_send 函数中的:

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无法发送邮件

  1. 大哥,看了你的设置很是迷糊啊,我这边设置mantis的邮件老是报错Testing Mail – int(1) string(70) “ERROR: Message could not be sent – SMTP Error: Could not authenticate.” PROBLEMS SENDING MAIL TO: xxx@xxx.cn. Please check your php/mail server settings.

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="">

请选择吧!