Commit 6c9bb074 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3701 / sendmail: Systemwide setting to redirect all QFQ generated mail to one specific account

config.qfq.ini: REDIRECT_ALL_MAIL_TO = john@doe.com
All emails, sent bey QFQ will not be sent to the given receiver, instead they are delivered to 'catch all email' address.
Sendmail.php: Check config.qfq.ini setting for REDIRECT_ALL_MAIL_TO - if set take that address as real receiver for all mails from Form and Report.
parent c85225cd
...@@ -222,6 +222,8 @@ config.qfq.ini ...@@ -222,6 +222,8 @@ config.qfq.ini
| SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | Possible values: auto|yes|no. For 'auto': If a BE User is logged in, | | SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | Possible values: auto|yes|no. For 'auto': If a BE User is logged in, |
| | | debug information will be shown on the fronend. | | | | debug information will be shown on the fronend. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+ +-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| REDIRECT_ALL_MAIL_TO | REDIRECT_ALL_MAIL_TO=john@doe.com | If set, redirect all QFQ generated mails (Form, Report) to the specified. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| CSS_LINK_CLASS_INTERNA L | CSS_LINK_CLASS_INTERNAL=internal | CSS class name of links which points to internal tagets | | CSS_LINK_CLASS_INTERNA L | CSS_LINK_CLASS_INTERNAL=internal | CSS class name of links which points to internal tagets |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+ +-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| CSS_LINK_CLASS_EXTERNAL | CSS_LINK_CLASS_EXTERNAL=external | CSS class name of links which points to internal tagets | | CSS_LINK_CLASS_EXTERNAL | CSS_LINK_CLASS_EXTERNAL=external | CSS class name of links which points to internal tagets |
...@@ -433,7 +435,9 @@ QFQ Keywords (Bodytext) ...@@ -433,7 +435,9 @@ QFQ Keywords (Bodytext)
Debug Debug
^^^^^ ^^^^^
* config.ini: *SHOW_DEBUG_INFO = yes|no|auto* `config.qfq.ini`_
* *SHOW_DEBUG_INFO = yes|no|auto*
* *yes*: * *yes*:
...@@ -453,6 +457,18 @@ Debug ...@@ -453,6 +457,18 @@ Debug
* *SHOW_DEBUG_INFO = yes* (BE session exist) * *SHOW_DEBUG_INFO = yes* (BE session exist)
* *SHOW_DEBUG_INFO = no* (no BE session) * *SHOW_DEBUG_INFO = no* (no BE session)
.. _REDIRECT_ALL_MAIL_TO:
* *REDIRECT_ALL_MAIL_TO=john@doe.com*
* During the development, it might be helpful to configure a 'catch all' email address, which QFQ uses as the final receiver
instead of the original intended one.
* The setting will:
* Replace the 'To' with the configured one.
* Clear 'CC' and 'Bcc'
* Write a note and the original configured receiver at the top of the email body.
.. _variables: .. _variables:
...@@ -2532,6 +2548,7 @@ Type: sendmail ...@@ -2532,6 +2548,7 @@ Type: sendmail
* To use values of the submitted form, use the STORE_FORM. E.g. `{{name:F:allbut}}` * To use values of the submitted form, use the STORE_FORM. E.g. `{{name:F:allbut}}`
* To use the `id` of a new created or already existing one, use the STORE_RECORD. E.g. `{{id:R}}` * To use the `id` of a new created or already existing one, use the STORE_RECORD. E.g. `{{id:R}}`
* For debugging, please check `REDIRECT_ALL_MAIL_TO`_.
.. _dynamic-update: .. _dynamic-update:
...@@ -4127,6 +4144,8 @@ This will send an email with subject *Latest News* from company@example.com to c ...@@ -4127,6 +4144,8 @@ This will send an email with subject *Latest News* from company@example.com to c
using a realname for customer2 and customer3 and suppress generating of OoO answer if any receiver is on vacation. using a realname for customer2 and customer3 and suppress generating of OoO answer if any receiver is on vacation.
Additional the CEO as well as backup will receive the mail via CC and BCC. Additional the CEO as well as backup will receive the mail via CC and BCC.
For debugging, please check `REDIRECT_ALL_MAIL_TO`_.
Column: _img Column: _img
^^^^^^^^^^^^ ^^^^^^^^^^^^
......
...@@ -18,6 +18,8 @@ SQL_LOG_MODE = modify ...@@ -18,6 +18,8 @@ SQL_LOG_MODE = modify
; auto|yes|no. 'auto': if BE User is logged in the value will be 'true', else 'false' ; auto|yes|no. 'auto': if BE User is logged in the value will be 'true', else 'false'
SHOW_DEBUG_INFO = auto SHOW_DEBUG_INFO = auto
; REDIRECT_ALL_MAIL_TO = john.doe@example.com
CSS_LINK_CLASS_INTERNAL = internal CSS_LINK_CLASS_INTERNAL = internal
CSS_LINK_CLASS_EXTERNAL = external CSS_LINK_CLASS_EXTERNAL = external
......
...@@ -324,6 +324,7 @@ const SYSTEM_DB_INIT = 'DB_INIT'; ...@@ -324,6 +324,7 @@ const SYSTEM_DB_INIT = 'DB_INIT';
const SYSTEM_SQL_LOG = 'SQL_LOG'; // Logging to file const SYSTEM_SQL_LOG = 'SQL_LOG'; // Logging to file
const SYSTEM_SQL_LOG_MODE = 'SQL_LOG_MODE'; // Mode, which statements to log. const SYSTEM_SQL_LOG_MODE = 'SQL_LOG_MODE'; // Mode, which statements to log.
const SYSTEM_DATE_FORMAT = 'DATE_FORMAT'; const SYSTEM_DATE_FORMAT = 'DATE_FORMAT';
const SYSTEM_REDIRECT_ALL_MAIL_TO = 'REDIRECT_ALL_MAIL_TO';
const SYSTEM_SHOW_DEBUG_INFO = 'SHOW_DEBUG_INFO'; const SYSTEM_SHOW_DEBUG_INFO = 'SHOW_DEBUG_INFO';
const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL'; const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL';
......
...@@ -6,6 +6,8 @@ namespace qfq; ...@@ -6,6 +6,8 @@ namespace qfq;
require_once(__DIR__ . '/../Constants.php'); require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../database/Database.php'); require_once(__DIR__ . '/../database/Database.php');
require_once(__DIR__ . '/../store/Store.php');
class Sendmail { class Sendmail {
...@@ -31,6 +33,8 @@ class Sendmail { ...@@ -31,6 +33,8 @@ class Sendmail {
*/ */
public function __construct(array $mailarr) { public function __construct(array $mailarr) {
$addBody = '';
// If there is no 'Receiver': do not send a mail. // If there is no 'Receiver': do not send a mail.
if (!isset($mailarr[SENDMAIL_IDX_RECEIVER]) || $mailarr[SENDMAIL_IDX_RECEIVER] === '') { if (!isset($mailarr[SENDMAIL_IDX_RECEIVER]) || $mailarr[SENDMAIL_IDX_RECEIVER] === '') {
return; return;
...@@ -40,8 +44,24 @@ class Sendmail { ...@@ -40,8 +44,24 @@ class Sendmail {
throw new UserFormException("Error sendmail missing one of: receiver, sender, subject or body", ERROR_SENDMAIL_MISSING_VALUE); throw new UserFormException("Error sendmail missing one of: receiver, sender, subject or body", ERROR_SENDMAIL_MISSING_VALUE);
} }
$store = Store::getInstance('');
$redirectAllMail = $store->getVar(SYSTEM_REDIRECT_ALL_MAIL_TO, STORE_SYSTEM);
if ($redirectAllMail !== false) {
$addBody .= "All QFQ outgoing mails are catched and redirected to you." . PHP_EOL . "Original receiver:" . PHP_EOL;
$addBody .= 'TO: ' . $mailarr[SENDMAIL_IDX_RECEIVER] . PHP_EOL;
$addBody .= 'CC: ' . $mailarr[SENDMAIL_IDX_RECEIVER_CC] . PHP_EOL;
$addBody .= 'BCC: ' . $mailarr[SENDMAIL_IDX_RECEIVER_BCC] . PHP_EOL;
$addBody .= PHP_EOL . "==========================================" . PHP_EOL . PHP_EOL;
$mailarr[SENDMAIL_IDX_RECEIVER] = $redirectAllMail;
$mailarr[SENDMAIL_IDX_RECEIVER_CC] = '';
$mailarr[SENDMAIL_IDX_RECEIVER_BCC] = '';
}
$header = $this->buildHeader($mailarr); $header = $this->buildHeader($mailarr);
if (!(mb_send_mail($mailarr[SENDMAIL_IDX_RECEIVER], $mailarr[SENDMAIL_IDX_SUBJECT], $mailarr[SENDMAIL_IDX_BODY], $header, "-f " . $mailarr[SENDMAIL_IDX_SENDER]))) {
if (!(mb_send_mail($mailarr[SENDMAIL_IDX_RECEIVER], $mailarr[SENDMAIL_IDX_SUBJECT], $addBody . $mailarr[SENDMAIL_IDX_BODY], $header, "-f " . $mailarr[SENDMAIL_IDX_SENDER]))) {
throw new UserFormException("Error sendmail failed.", ERROR_SENDMAIL); throw new UserFormException("Error sendmail failed.", ERROR_SENDMAIL);
} }
...@@ -49,10 +69,10 @@ class Sendmail { ...@@ -49,10 +69,10 @@ class Sendmail {
} }
/** /**
* @param $mailarr * @param array $mailarr
* @return string * @return string
*/ */
private function buildHeader($mailarr) { private function buildHeader(array $mailarr) {
// "\r\n" needs to be enclosed in double ticks to correctly converted to 0x0d 0x0a, // "\r\n" needs to be enclosed in double ticks to correctly converted to 0x0d 0x0a,
$header = "From: " . $mailarr[SENDMAIL_IDX_SENDER] . "\r\n"; $header = "From: " . $mailarr[SENDMAIL_IDX_SENDER] . "\r\n";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment