From 29d7492b39f16400ccd8c2885db657f9af9de4d5 Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Tue, 9 May 2023 13:06:19 +0100 Subject: [PATCH] dev/core#4273 - CRM/Mailing - Allow user to configure donotreply from email address --- CRM/Admin/Form/Preferences/Mailing.php | 13 +++++++++++ CRM/Core/BAO/Domain.php | 9 +++++++- settings/Mailing.setting.php | 22 +++++++++++++++++++ .../CRM/Admin/Form/Preferences/Mailing.hlp | 18 +++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 templates/CRM/Admin/Form/Preferences/Mailing.hlp diff --git a/CRM/Admin/Form/Preferences/Mailing.php b/CRM/Admin/Form/Preferences/Mailing.php index 23cc19a9b8cb..1e8a22f083b2 100644 --- a/CRM/Admin/Form/Preferences/Mailing.php +++ b/CRM/Admin/Form/Preferences/Mailing.php @@ -22,6 +22,7 @@ class CRM_Admin_Form_Preferences_Mailing extends CRM_Admin_Form_Preferences { protected $_settings = [ 'profile_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, + 'not_reply_email_address' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'profile_add_to_group_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_workflow' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, @@ -63,4 +64,16 @@ public function postProcess() { parent::postProcess(); } + /** + * @return array + */ + public static function getAvailableFromEmailAddress() { + $fromAddress[NULL] = ts(''); + $addresses = CRM_Core_OptionGroup::values('from_email_address'); + foreach ($addresses as $key => $value) { + $fromAddress[$key] = $value; + } + return $fromAddress; + } + } diff --git a/CRM/Core/BAO/Domain.php b/CRM/Core/BAO/Domain.php index b81d5add43bb..50a67b9fffc5 100644 --- a/CRM/Core/BAO/Domain.php +++ b/CRM/Core/BAO/Domain.php @@ -366,7 +366,14 @@ public static function getDefaultReceiptFrom() { */ public static function getNoReplyEmailAddress() { $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); - return "do-not-reply@$emailDomain"; + $notReplyEmailAddress = \Civi::settings()->get('not_reply_email_address'); + + if (!empty($notReplyEmailAddress)) { + $notReplyEmailAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND value = '.$notReplyEmailAddress); + $notReplyEmailAddress = current($notReplyEmailAddress); + } + + return $notReplyEmailAddress ?: "do-not-reply@$emailDomain"; } } diff --git a/settings/Mailing.setting.php b/settings/Mailing.setting.php index 434e78a7ee38..4ca72f8cf503 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -33,6 +33,28 @@ 'description' => ts('When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.'), 'help_text' => NULL, ], + 'not_reply_email_address' => [ + 'group_name' => 'Mailing Preferences', + 'group' => 'mailing', + 'name' => 'not_reply_email_address', + 'type' => 'String', + 'quick_form_type' => 'Select', + 'html_type' => 'select', + 'html_attributes' => [ + 'class' => 'crm-select2', + ], + 'default' => NULL, + 'pseudoconstant' => [ + 'callback' => 'CRM_Admin_Form_Preferences_Mailing::getAvailableFromEmailAddress', + ], + 'add' => '5.63', + 'title' => ts('Email From Address to use where a reply is not expected'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => '', + 'help_text' => NULL, + 'help' => ['id' => 'not_reply_email_address'] + ], 'track_civimail_replies' => [ 'group_name' => 'Mailing Preferences', 'group' => 'mailing', diff --git a/templates/CRM/Admin/Form/Preferences/Mailing.hlp b/templates/CRM/Admin/Form/Preferences/Mailing.hlp new file mode 100644 index 000000000000..a3318ac49398 --- /dev/null +++ b/templates/CRM/Admin/Form/Preferences/Mailing.hlp @@ -0,0 +1,18 @@ +{* + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC. All rights reserved. | + | | + | This work is published under the GNU AGPLv3 license with some | + | permitted exceptions and without any warranty. For full license | + | and copyright information, see https://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +{htxt id="not_reply_email_address-title"} + {ts}Email From Address for no-reply emails.{/ts} +{/htxt} +{htxt id="not_reply_email_address"} + {capture assign=fromEmailOptionsURL}{crmURL p='civicrm/admin/options/from_email_address' q="reset=1"}{/capture} +

{ts 1=$fromEmailOptionsURL}Specify an Email From Address to use when the system sends an email but a reply is not expected, for example when a user is sent an email for a double opt-in.

+

Leaving this blank will use the default which will be do-not-reply@default_domain where the default_domain will be the email domain address of your default mailing account also used for bounce handling.

+

You can add additional Email From Addresses here.{/ts}

+{/htxt}