Skip to content

Commit 01afcb2

Browse files
Hackwarwilsonge
authored andcommitted
[4.0] Adding a mail templating system (#22126)
1 parent 9f4a63b commit 01afcb2

File tree

32 files changed

+2708
-9
lines changed

32 files changed

+2708
-9
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
2+
('com_mails', 'component', 'com_mails', '', 1, 1, 1, 1, '{"name":"com_mails","type":"component","creationDate":"January 2019","author":"Joomla! Project","copyright":"(C) 2005 - 2018 Open Source Matters. All rights reserved.","authorEmail":"[email protected]","authorUrl":"www.joomla.org","version":"4.0.0","description":"COM_MAILS_XML_DESCRIPTION","group":""}', '{}', 0, '0000-00-00 00:00:00', 0, 0);
3+
4+
CREATE TABLE IF NOT EXISTS `#__mail_templates` (
5+
`template_id` VARCHAR(127) NOT NULL DEFAULT '',
6+
`language` char(7) NOT NULL DEFAULT '',
7+
`subject` VARCHAR(255) NOT NULL DEFAULT '',
8+
`body` TEXT NOT NULL,
9+
`htmlbody` TEXT NOT NULL,
10+
`attachments` TEXT NOT NULL,
11+
`params` TEXT NOT NULL,
12+
PRIMARY KEY (`template_id`, `language`)
13+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
14+
15+
INSERT INTO `#__mail_templates` (`template_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
INSERT INTO "#__extensions" ("name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "checked_out", "checked_out_time", "ordering", "state") VALUES
2+
('com_mails', 'component', 'com_mails', '', 1, 1, 1, 1, '{"name":"com_mails","type":"component","creationDate":"January 2019","author":"Joomla! Project","copyright":"(C) 2005 - 2019 Open Source Matters. All rights reserved.","authorEmail":"[email protected]","authorUrl":"www.joomla.org","version":"4.0.0","description":"COM_MAILS_XML_DESCRIPTION","group":""}', '{}', 0, '1970-01-01 00:00:00', 0, 0);
3+
4+
CREATE TABLE IF NOT EXISTS "#__mail_templates" (
5+
"template_id" varchar(127) NOT NULL DEFAULT '',
6+
"language" char(7) NOT NULL DEFAULT '',
7+
"subject" varchar(255) NOT NULL DEFAULT '',
8+
"body" TEXT NOT NULL,
9+
"htmlbody" TEXT NOT NULL,
10+
"attachments" TEXT NOT NULL,
11+
"params" TEXT NOT NULL,
12+
CONSTRAINT "#__mail_templates_idx_template_id_language" UNIQUE ("template_id", "language")
13+
);
14+
CREATE INDEX "#__mail_templates_idx_template_id" ON "#__mail_templates" ("template_id");
15+
CREATE INDEX "#__mail_templates_idx_language" ON "#__mail_templates" ("language");
16+
17+
INSERT INTO "#__mail_templates" ("template_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');

administrator/components/com_config/Model/ApplicationModel.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Joomla\CMS\Http\HttpFactory;
2525
use Joomla\CMS\Language\Text;
2626
use Joomla\CMS\Log\Log;
27+
use Joomla\CMS\Mail\MailTemplate;
2728
use Joomla\CMS\MVC\Model\FormModel;
2829
use Joomla\CMS\Table\Asset;
2930
use Joomla\CMS\Table\Table;
@@ -1014,6 +1015,7 @@ public function sendTestMail()
10141015
{
10151016
// Set the new values to test with the current settings
10161017
$app = Factory::getApplication();
1018+
$user = Factory::getUser();
10171019
$input = $app->input->json;
10181020

10191021
$app->set('smtpauth', $input->get('smtpauth'));
@@ -1029,11 +1031,17 @@ public function sendTestMail()
10291031

10301032
$mail = Factory::getMailer();
10311033

1032-
// Prepare email and send try to send it
1033-
$mailSubject = Text::sprintf('COM_CONFIG_SENDMAIL_SUBJECT', $app->get('sitename'));
1034-
$mailBody = Text::sprintf('COM_CONFIG_SENDMAIL_BODY', Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer)));
1034+
// Prepare email and try to send it
1035+
$mailer = new MailTemplate('com_config.test_mail', $user->getParam('language', $app->get('language')), $mail);
1036+
$mailer->addTemplateData(
1037+
array(
1038+
'sitename' => $app->get('sitename'),
1039+
'method' => Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer))
1040+
)
1041+
);
1042+
$mailer->addRecipient($app->get('mailfrom'), $app->get('fromname'));
10351043

1036-
if ($mail->sendMail($app->get('mailfrom'), $app->get('fromname'), $app->get('mailfrom'), $mailSubject, $mailBody) === true)
1044+
if ($mailer->send() === true)
10371045
{
10381046
$methodName = Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer));
10391047

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_mails
5+
*
6+
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\Component\Mails\Administrator\Controller;
11+
12+
defined('_JEXEC') or die;
13+
14+
use Joomla\CMS\MVC\Controller\BaseController;
15+
16+
/**
17+
* Mail templates Controller
18+
*
19+
* @since __DEPLOY_VERSION__
20+
*/
21+
class DisplayController extends BaseController
22+
{
23+
/**
24+
* The default view.
25+
*
26+
* @var string
27+
* @since 1.6
28+
*/
29+
protected $default_view = 'templates';
30+
}

0 commit comments

Comments
 (0)