Problems with emails

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Problems with emails

Post by TrevorCui »

Hello Gyus,
First of all, I hope you are well who is seeing this message.
I've been having a problem about Mantis mail configuration recently. so, I hope I can find the help here to solve it. Below is some of my configuration information for Mantis's mail feature.
Mantis version:2.24.1 (installed base on xampp 7.4.7)
php vesion:7.4.7

Because this vesion of Mantis has no PHPmailer, so I have download one and stored in C:\xampp\htdocs\mantis\library\phpmailer.
in fact, I have only do some change in config.inc.php , config_default_inc.php and php.ini like below:

config.inc.php
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$g_smtp_host = 'smtp.163.com'; # SMTP server MUST BE configured
$g_tl_admin_email = 'Trevor.Cui@metasystem.cn'; # for problem/error notification
$g_from_email = 'msc_mantis@163.com'; # email sender
$g_return_path_email = 'msc_mantis@163.com';
$g_webmaster_email = 'Trevor.Cui@metasystem.cn';
$g_default_notify_flags = array(
'reporter' => ON,
'handler' => ON,
'monitor' => ON,
'bugnotes' => ON,
'category' => ON,
'explicit' => ON,
'threshold_min' => NOBODY,
'threshold_max' => NOBODY
);

$g_mail_priority = 1;
$g_enable_email_notification = ON;
$g_email_notifications_verbose = ON;
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
$g_use_phpMailer = ON;
$g_phpMailer_path = ’C:\xampp\htdocs\mantis\library\phpmailer’;
$g_smtp_username = 'msc_mantis'; # user
$g_smtp_password = '*************'; # SMTP authorization code
$g_email_receive_own = ON;
$g_email_send_using_cronjob = ON;
$g_smtp_connection_mode = 'ssl';
$g_smtp_port = 465;
$g_SMTPAutoTLS = false;
//////////////////////////////////////////////////////////////////////////////////////////////////////////

I have keeped the same config in config_default_inc.php.

php.ini
//////////////////////////////////////////////////////////////////////////////////////////////////////////
[mail function]
SMTP = smtp.163.com
smtp_port= 465
sendmail_from = msc_mantis@163.com
sendmail_path = /usr/sbin/sendmail -t -f
//////////////////////////////////////////////////////////////////////////////////////////////////////////

In addition, I need to note that I wrote a sendMaile.php to verify the email password and port, and it can send emails.So my email account and Port Settings are all OK.

If you know how to solve this problem, would you like to help me? I would be very grateful.

My email address is trevor.cui@metasystem.cn.

Whether the problem can be solved or not, I wish you happiness who is in front of the screen.

Looking forward to your reply and thank you inadvance.

Best regards,
Trevor
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Please read this if you have problems with emails

Post by atrol »

TrevorCui wrote: 25 Jun 2021, 05:39 Mantis version:2.24.1 (installed base on xampp 7.4.7)
Because this vesion of Mantis has no PHPmailer
Sure? https://sourceforge.net/projects/mantis ... p/download
TrevorCui wrote: 25 Jun 2021, 05:39I have only do some change in config.inc.php , config_default_inc.php
Never ever change config_default_inc.php, there is no reason for it. All configuration must be done in config.inc.php
Please use Search before posting and read the Manual
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Please read this if you have problems with emails

Post by TrevorCui »

Hello Atrol,
thank you for your kindly help.
I have download the new one from the link which you shared to me. And I have use Compare tool to compare these two version of Mantis 2.24.1. I found besides phpmailer, there is no any other diffrence. So, I have copy the PHPmailer from the new one to the old one.
Then, I follow your advice, recover the config_defaults_inc.php. I have only change in config.inc.php which stored in mantis\config folder. Here is my setup:

config.inc.php
///////////////////////////////////////////////////////////////////////////////
<?php
# MantisBT - A PHP based bugtracking system
# Configed by Trevor Cui


$g_hostname = 'localhost';
$g_db_type = 'mysqli';
$g_database_name = 'bugtracker';
$g_db_username = 'root';
$g_db_password = '';
$g_default_timezone = 'Europe/Berlin';
$g_crypto_master_salt = 'BowGwb84c1P+3+vyRqgq4sMO48n7uooK8nK+YtIpjjo=';

# --- Email Configuration ---
$g_phpMailer_method = PHPMAILER_METHOD_SMTP; # or PHPMAILER_METHOD_SMTP, PHPMAILER_METHOD_SENDMAIL
$g_smtp_host = 'smtp.163.com'; # used with PHPMAILER_METHOD_SMTP
$g_smtp_port = 465;
$g_smtp_connection_mode ='ssl';
$g_smtp_username = 'msc_mantis'; # used with PHPMAILER_METHOD_SMTP
$g_smtp_password = 'DWSKTKYGPVYN****'; # used with PHPMAILER_METHOD_SMTP
$g_webmaster_email = 'trevor.cui@metasystem.cn';
$g_from_email = 'msc_mantis@163.com'; # the "From: " field in emails
$g_return_path_email = 'msc_mantis@163.com'; # the return address for bounced mail
$g_from_name = 'Mantis Bug Tracker';
$g_email_receive_own = ON;
$g_email_send_using_cronjob = ON;
$g_enable_email_notification = ON;
$g_email_notifications_verbose =ON;
$g_validate_email = OFF;
$g_check_mx_record = OFF;
$g_allow_blank_email =ON;
$g_email_login_enabled=ON;
$g_email_ensure_unique=ON;
$g_limit_email_domains = array( 'users.sourceforge.net', 'sourceforge.net' );
$g_email_retry_in_days =7;
$g_phpMailer_path = 'C:\xampp\htdocs\mantis\vendor\phpmailer';


# MantisBT Language Settings #

$g_default_language = 'chinese_simplified';

/**
* limit by days
* @global integer $g_news_view_limit_days
*/
$g_news_view_limit_days = 60;

/**
* Maximum file size (bytes) that can be uploaded.
* Also check your PHP settings (default is usually 2MBs)
* @global integer $g_max_file_size
*/
$g_max_file_size = 20000000;

/**
* Maximum number of files that can be uploaded simultaneously
* @global integer $g_file_upload_max_num
*/
$g_file_upload_max_num = 20;




# --- Attachments / File Uploads ---
# $g_allow_file_upload = ON;
# $g_file_upload_method = DATABASE; # or DISK
# $g_absolute_path_default_upload_folder = ''; # used with DISK, must contain trailing \ or /.
#$g_max_file_size = 5000000; # in bytes
# $g_preview_attachments_inline_max_size = 256 * 1024;
# $g_allowed_files = ''; # extensions comma separated, e.g. 'php,html,java,exe,pl'
# $g_disallowed_files = ''; # extensions comma separated

# --- Branding ---
# $g_window_title = 'MantisBT';
# $g_logo_image = 'images/mantis_logo.png';
# $g_favicon_image = 'images/favicon.ico';

# --- Real names ---
$g_show_realname = ON;
# $g_show_user_realname_threshold = NOBODY; # Set to access level (e.g. VIEWER, REPORTER, DEVELOPER, MANAGER, etc)

# --- Others ---
# $g_default_home_page = 'my_view_page.php'; # Set to name of page to go to after login

//////////////////////////////////////////////////////////////////////////////////////////

php.ini is the same as I shared before.

I found it still not work. By the way, I also ensure that php_openssl has been enabled.

should I do some change in phpmailer?

could you please help me to solve this problem? thank you in advance.

Best regards,
Trevor
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Problems with emails

Post by atrol »

Is it intended that you have set
$g_limit_email_domains = array( 'users.sourceforge.net', 'sourceforge.net' );
Please use Search before posting and read the Manual
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Problems with emails

Post by TrevorCui »

Hello Atrol,
I saw this configration in Admin Guide 'Only allow and send email to addresses in the given domain(s). This is useful as a security feature and it is also useful in cases like Sourceforge where its servers are limited to only sending emails to SourceForge email addresses in order to avoid spam. $g_limit_email_domains = array( 'users.sourceforge.net', 'sourceforge.net' ); '
I blocked it later and it still didn't work.
As I know, I just need to change config.inc.php and php.ini. I think all the config is right. Besides, I used sendmaile.php to send an emaile, it successed.

/////////////////////////// sendmaile.php /////////////////////////////////////////////////
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require './src/Exception.php';
require './src/PHPMailer.php';
require './src/SMTP.php';

$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//服务器配置
$mail->CharSet ="UTF-8"; //设定邮件编码
$mail->SMTPDebug = 0; // 调试模式输出
$mail->isSMTP(); // 使用SMTP
$mail->Host = 'smtp.163.com'; // SMTP服务器
$mail->SMTPAuth = true; // 允许 SMTP 认证
$mail->Username = 'msc_mantis'; // SMTP 用户名 即邮箱的用户名
$mail->Password = '**********'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
$mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
$mail->Port = 465; // 服务器端口 25 或者465 具体要看邮箱服务器支持

$mail->setFrom('msc_mantis@163.com', 'Mailer'); //发件人
$mail->addAddress('trevor.cui@metasystem.cn', 'Trevor'); // 收件人
//$mail->addAddress('ellen@example.com'); //可添加多个收件人
$mail->addReplyTo('msc_mantis@163.com@163.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
//$mail->addCC('cc@example.com'); //抄送
//$mail->addBCC('bcc@example.com'); //密送

//发送附件
// $mail->addAttachment('../xy.zip'); // 添加附件
// $mail->addAttachment('../thumb-1.jpg', 'new.jpg'); // 发送附件并且重命名

//Content
$mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
$mail->Subject = 'email debug' . time();
$mail->Body = 'test email' . date('Y-m-d H:i:s');
$mail->AltBody = 'Display this content if the mail client does not support HTML';

$mail->send();
echo 'send an e-mail success';
} catch (Exception $e) {
echo 'e-mail sending failed: ', $mail->ErrorInfo;
}

/////////////////////////// // /////////////////////////////////////////////////

In other words, there is no problem with my email account and port.

Is there anything I haven't considered?

thank you again for your reply, and waiting your feedback.

Best regards,
Trevor
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Problems with emails

Post by TrevorCui »

Hello Atrol,
my problem seems be solved. I have keeped the same config in config_inc.php and config_defaults_inc.php.
In addition,I have add one line code in php.ini:
include_path="C:\xampp\htdocs\mantis\vendor\phpmailer"
And then, I can receive the email from mantis.



Thank you for your kindly help.
Best regards,
Trevor
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Problems with emails

Post by TrevorCui »

Hello Atrol,
Another question. In order to improve the smoothness of the web page, I turned on the email on time delivery service that I set $g_email_send_using_cronjob = ON;
But how can I adjust the timing frequency?

Looking farward to your reply and thank you inadvance.

Best regards,
Trevor
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Problems with emails

Post by atrol »

See documentation
Emails are instead queued and must be sent by running scripts/send_emails.php periodically
You have to setup a job in Windows that runs the script. (Windows Task Scheduler or any other tool that is available on Windows for it)
That's the place where you configure the frequency.
Please use Search before posting and read the Manual
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Problems with emails

Post by TrevorCui »

Hello Atrol,
I have written a .bat script file to run send_emails.php, and add this task as a windows regular task. This sript will runing every minutes.
But there is still a huge pile of unsent mail in the emaile_table.

////////////////////////////////////////Auto_send_emaile///////////////

start / "C:\xampp\php" php-cgi.exe "C:\xampp\htdocs\mantis\scripts\send_emails.php"

//////////////////////////////////////////////////////////////////////

could you please help me to have a check. thank you very much.

Best regards,
Trevor
Attachments
Auo_send_emaile.PNG
Auo_send_emaile.PNG (53.39 KiB) Viewed 15026 times
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Problems with emails

Post by atrol »

TrevorCui wrote: 05 Jul 2021, 07:31 But there is still a huge pile of unsent mail in the emaile_table.
This is ertainly the reason for your performance issues.

Are at least some emails sent when using the bat script?

BTW, running the .bat script every minute will slow down your system even more if there are lot of entries in email_table.
Please use Search before posting and read the Manual
TrevorCui
Posts: 8
Joined: 25 Jun 2021, 04:42

Re: Problems with emails

Post by TrevorCui »

Hello Atrol,
Thank you for your help. It works well now. it seems there have some wrong with my script.
Finaly, it be realized by reseting the windows timing task as below:
Perform regular procedures:C:\xampp\php\php.exe with parameter: C:\xampp\htdocs\mantis\scripts\send_emails.php
Thank you for your help again.

Best regards,
Trevor
Post Reply