Skip to content

Commit c6d50cf

Browse files
authored
NEW(mailing): Allow user to define the number of email sent by batch directly from mailing config page (#32750)
* NEW(mailing): Allow user to define the number of email sent by batch * FIX: incompatibility with conf.php fie * DEL: MAILING_LIMIT_SENDBYWEB constant from const.php page * Define the const for all entities instead of specific entity * Remove note --------- Co-authored-by: Benjamin Falière <benjamin.faliere@altairis.fr>
1 parent b16b462 commit c6d50cf

4 files changed

Lines changed: 48 additions & 23 deletions

File tree

htdocs/admin/mailing.php

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
44
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
55
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6+
* Copyright (C) 2025 Benjamin Falière <benjamin@faliere.com>
67
*
78
* This program is free software; you can redistribute it and/or modify
89
* it under the terms of the GNU General Public License as published by
@@ -26,8 +27,8 @@
2627

2728
// Load Dolibarr environment
2829
require '../main.inc.php';
29-
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30-
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
30+
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
31+
require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
3132

3233
/**
3334
* @var Conf $conf
@@ -63,11 +64,14 @@
6364
$checkread = GETPOST('value', 'alpha');
6465
$checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
6566
$contactbulkdefault = GETPOSTINT('MAILING_CONTACT_DEFAULT_BULK_STATUS');
67+
$batchlimit = GETPOSTINT('MAILING_LIMIT_SENDBYWEB');
68+
6669
if (GETPOST('MAILING_DELAY', 'alpha') != '') {
6770
$mailingdelay = price2num(GETPOST('MAILING_DELAY', 'alpha'), 3); // Not less than 1 millisecond.
6871
} else {
6972
$mailingdelay = '';
7073
}
74+
7175
// Clean data
7276
if ((float) $mailingdelay > 10) {
7377
$mailingdelay = 10;
@@ -92,6 +96,10 @@
9296
if (!($res > 0)) {
9397
$error++;
9498
}
99+
$res = dolibarr_set_const($db, "MAILING_LIMIT_SENDBYWEB", $batchlimit, 'chaine', 1, '', 0);
100+
if (!($res > 0)) {
101+
$error++;
102+
}
95103

96104
// Create temporary encryption key if needed
97105
$res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
@@ -127,51 +135,52 @@
127135

128136
llxHeader('', $langs->trans("MailingSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-mailing');
129137

130-
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
138+
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
131139
print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
132140

133141
$constname = 'MAILING_EMAIL_UNSUBSCRIBE_KEY';
134142

135143
// Add button to autosuggest a key
136-
include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
144+
include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
137145
print dolJSToSetRandomPassword($constname);
138146

139147
print '<br>';
140-
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
141-
print '<input type="hidden" name="token" value="'.newToken().'">';
148+
print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">';
149+
print '<input type="hidden" name="token" value="' . newToken() . '">';
142150
print '<input type="hidden" name="action" value="setvalue">';
143151

144152
print '<table class="noborder centpercent">';
145153
print '<tr class="liste_titre">';
146154
print '<td>'.$langs->trans("Parameter").'</td>';
147155
print '<td></td>';
148156
print '<td class="hideonsmartphone">'.$langs->trans("Example").'</td>';
157+
149158
print "</tr>\n";
150159

151160
print '<tr class="oddeven"><td>';
152161
$help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
153-
print $langs->trans("MailingEMailFrom").' '.$help.'</td><td>';
154-
print '<input class="minwidth100" type="text" name="MAILING_EMAIL_FROM" value="' . getDolGlobalString('MAILING_EMAIL_FROM').'">';
162+
print $langs->trans("MailingEMailFrom") . ' ' . $help . '</td><td>';
163+
print '<input class="minwidth100" type="text" name="MAILING_EMAIL_FROM" value="' . getDolGlobalString('MAILING_EMAIL_FROM') . '">';
155164
if (getDolGlobalString('MAILING_EMAIL_FROM') && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) {
156-
print ' '.img_warning($langs->trans("BadEMail"));
165+
print ' ' . img_warning($langs->trans("BadEMail"));
157166
}
158167
print '</td>';
159-
print '<td class="hideonsmartphone"><span class="opacitymedium">'.dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName').' <noreply@example.com>').'</span></td>';
168+
print '<td class="hideonsmartphone"><span class="opacitymedium">' . dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName') . ' <noreply@example.com>') . '</span></td>';
160169
print '</tr>';
161170

162171
print '<tr class="oddeven"><td>';
163-
print $langs->trans("MailingEMailError").'</td><td>';
164-
print '<input class="minwidth100" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.getDolGlobalString('MAILING_EMAIL_ERRORSTO').'">';
172+
print $langs->trans("MailingEMailError") . '</td><td>';
173+
print '<input class="minwidth100" type="text" name="MAILING_EMAIL_ERRORSTO" value="' . getDolGlobalString('MAILING_EMAIL_ERRORSTO') . '">';
165174
if (getDolGlobalString('MAILING_EMAIL_ERRORSTO') && !isValidEmail(getDolGlobalString('MAILING_EMAIL_ERRORSTO'))) {
166-
print ' '.img_warning($langs->trans("BadEMail"));
175+
print ' ' . img_warning($langs->trans("BadEMail"));
167176
}
168177
print '</td>';
169-
print '<td class="hideonsmartphone"><span class="opacitymedium">'.dol_escape_htmltag('<webmaster@example.com>').'</span></td>';
178+
print '<td class="hideonsmartphone"><span class="opacitymedium">' . dol_escape_htmltag('<webmaster@example.com>') . '</span></td>';
170179
print '</tr>';
171180

172181
print '<tr class="oddeven"><td>';
173-
print $form->textwithpicto($langs->trans("MailingDelay"), $langs->trans("IfDefinedUseAValueBeetween", '0.001', '10')).'</td><td>';
174-
print '<input class="width75" type="text" name="MAILING_DELAY" value="'.getDolGlobalString('MAILING_DELAY').'">';
182+
print $form->textwithpicto($langs->trans("MailingDelay"), $langs->trans("IfDefinedUseAValueBeetween", '0.001', '10')) . '</td><td>';
183+
print '<input class="width75" type="text" name="MAILING_DELAY" value="' . getDolGlobalString('MAILING_DELAY') . '">';
175184
print '</td>';
176185
print '<td class="hideonsmartphone"></td>';
177186
print '</tr>';
@@ -181,10 +190,10 @@
181190
// It is also used as a security key parameter.
182191

183192
print '<tr class="oddeven"><td>';
184-
print $langs->trans("ActivateCheckReadKey").'</td><td>';
185-
print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY').'">';
193+
print $langs->trans("ActivateCheckReadKey") . '</td><td>';
194+
print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="' . getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY') . '">';
186195
if (!empty($conf->use_javascript_ajax)) {
187-
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
196+
print '&nbsp;' . img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
188197
}
189198
print '</td>';
190199
print '<td class="hideonsmartphone"></td>';
@@ -194,16 +203,27 @@
194203
print '<tr class="oddeven">';
195204
print '<td>' . $langs->trans("DefaultBlacklistMailingStatus", $langs->transnoentitiesnoconv("No_Email")) . '</td>';
196205
print '<td>';
197-
$blacklist_setting=array(0=>$langs->trans('No'), 1=>$langs->trans('Yes'), 2=>$langs->trans('DefaultStatusEmptyMandatory'));
206+
$blacklist_setting = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes'), 2 => $langs->trans('DefaultStatusEmptyMandatory'));
198207
print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, getDolGlobalString('MAILING_CONTACT_DEFAULT_BULK_STATUS'));
199208
print '</td>';
200209
print '<td class="hideonsmartphone"></td>';
201210
print '</tr>';
202211

212+
// Limit number for each mailing batch, displayed only if this value is not defined in the conf.php file
213+
if (empty($conf->file->mailing_limit_sendbyweb)) {
214+
print '<tr class="oddeven">';
215+
$help = img_help(1, $langs->trans("MailingNumberOfEmailsPerBatchHelp"));
216+
print '<td>' . $langs->trans("MailingNumberOfEmailsPerBatch") . ' ' . $help . '</td>';
217+
print '<td>';
218+
print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_LIMIT_SENDBYWEB" id="MAILING_LIMIT_SENDBYWEB" value="' . getDolGlobalString('MAILING_LIMIT_SENDBYWEB') . '">';
219+
print '</td>';
220+
print '<td class="hideonsmartphone"></td>';
221+
print '</tr>';
222+
}
203223

204224
if (!empty($conf->use_javascript_ajax) && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1) {
205225
print '<tr class="oddeven"><td>';
206-
print $langs->trans("MailAdvTargetRecipients").'</td><td>';
226+
print $langs->trans("MailAdvTargetRecipients") . '</td><td>';
207227
print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
208228
print '</td>';
209229
print '<td class="hideonsmartphone"></td>';

htdocs/install/mysql/data/llx_const.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
-- Visible in misc page and common to all entities
3535
insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_NOT_INSTALLED','1','chaine','Setup is running',1,0);
36-
insert into llx_const (name, value, type, note, visible, entity) values ('MAILING_LIMIT_SENDBYWEB','25','chaine','Number of targets to defined packet size when sending mass email',1,0);
37-
--insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_ENABLE_LOG_TO_HTML','0','chaine','If this option is set to 1, it is possible to see log output at end of HTML sources by adding parameter logtohtml=1 on URL. Module log must also be enabled.',1,0);
36+
--insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_ENABLE_LOG_TO_HTML','0','chaine','If this option is set to 1, it is possible to see log output at end of HTML sources by adding paramater logtohtml=1 on URL. Module log must also be enabled.',1,0);
3837

3938
-- Visible in misc page but specific to one entity
4039
insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_FEATURES_LEVEL','0','chaine','Level of features to show: -1=stable+deprecated, 0=stable only (default), 1=stable+experimental, 2=stable+experimental+development',1,__ENTITY__);
@@ -43,6 +42,8 @@ insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_F
4342
insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG_HANDLERS','["mod_syslog_file"]','chaine','Which logger to use',0,0);
4443
insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG_FILE','DOL_DATA_ROOT/dolibarr.log','chaine','Directory where to write log file',0,0);
4544
insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG_LEVEL','7','chaine','Level of debug info to show',0,0);
45+
insert into llx_const (name, value, type, note, visible, entity) values ('MAILING_LIMIT_SENDBYWEB','25','chaine','Number of targets to defined packet size when sending mass email',0,0);
46+
4647

4748
-- Hidden but specific to one entity
4849
insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_UPLOAD_DOC','2048','chaine','Max size for file upload (0 means no upload allowed)',0,__ENTITY__);

htdocs/install/mysql/migration/21.0.0-22.0.0.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ ALTER TABLE llx_societe_account ADD COLUMN ip varchar(250);
6363

6464
ALTER TABLE llx_product ADD COLUMN packaging float(24,8) DEFAULT NULL;
6565

66+
-- mailing
67+
UPDATE llx_const SET visible = 0 WHERE name='MAILING_LIMIT_SENDBYWEB';
6668

6769
ALTER TABLE llx_categorie_member ADD COLUMN import_key varchar(14);
6870
ALTER TABLE llx_category_bankline ADD COLUMN import_key varchar(14);

htdocs/langs/en_US/mails.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,5 @@ ContentOfMailHolder=Content of email goes here...
204204
LastNews=Latest News
205205
ListProducts= List of products
206206
PasswordReset=Password reset
207+
MailingNumberOfEmailsPerBatch=Number of emails per batch
208+
MailingNumberOfEmailsPerBatchHelp=Define the number of emails you want to send for each manual sending action. Warning: An important number of emails can lead to your server being blacklisted.

0 commit comments

Comments
 (0)