summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-18 17:17:40 -0500
committerGitHub <noreply@github.com>2017-04-18 17:17:40 -0500
commit4b2d594c70b32b499dbd1c872a3cedecb6cc22bf (patch)
tree72f4d70d697eab51ea8e3c15fa52a285f24cc5a7
parent47fe5e8f415ecd17d2755da7868651e214622238 (diff)
parent0a54d5a5dde832cc4353e91bd6e6af16e6e5c715 (diff)
downloadnextcloud-server-4b2d594c70b32b499dbd1c872a3cedecb6cc22bf.tar.gz
nextcloud-server-4b2d594c70b32b499dbd1c872a3cedecb6cc22bf.zip
Merge pull request #4379 from nextcloud/nicely-designed-confirmation-mail
Beautify test email
-rw-r--r--settings/Controller/MailSettingsController.php16
-rw-r--r--tests/Settings/Controller/MailSettingsControllerTest.php6
2 files changed, 18 insertions, 4 deletions
diff --git a/settings/Controller/MailSettingsController.php b/settings/Controller/MailSettingsController.php
index f0fd7a52f0b..ed742059665 100644
--- a/settings/Controller/MailSettingsController.php
+++ b/settings/Controller/MailSettingsController.php
@@ -145,11 +145,19 @@ class MailSettingsController extends Controller {
$email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
if (!empty($email)) {
try {
+ $displayName = $this->userSession->getUser()->getDisplayName();
+
+ $template = $this->mailer->createEMailTemplate();
+ $template->addHeader();
+ $template->addHeading($this->l10n->t('Well done, %s!', [$displayName]));
+ $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.'));
+ $template->addFooter();
+
$message = $this->mailer->createMessage();
- $message->setTo([$email => $this->userSession->getUser()->getDisplayName()]);
- $message->setFrom([$this->defaultMailAddress]);
- $message->setSubject($this->l10n->t('test email settings'));
- $message->setPlainBody('If you received this email, the settings seem to be correct.');
+ $message->setTo([$email => $displayName]);
+ $message->setSubject($this->l10n->t('Email setting test'));
+ $message->setHtmlBody($template->renderHTML());
+ $message->setPlainBody($template->renderText());
$errors = $this->mailer->send($message);
if (!empty($errors)) {
throw new \RuntimeException($this->l10n->t('Mail could not be sent. Check your mail server log'));
diff --git a/tests/Settings/Controller/MailSettingsControllerTest.php b/tests/Settings/Controller/MailSettingsControllerTest.php
index c8f9e476801..79fe0683cc5 100644
--- a/tests/Settings/Controller/MailSettingsControllerTest.php
+++ b/tests/Settings/Controller/MailSettingsControllerTest.php
@@ -20,6 +20,7 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
+use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OC\User\User;
@@ -161,6 +162,11 @@ class MailSettingsControllerTest extends \Test\TestCase {
$this->mailer->expects($this->once())
->method('createMessage')
->willReturn($this->createMock(Message::class));
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $this->mailer
+ ->expects($this->once())
+ ->method('createEMailTemplate')
+ ->willReturn($emailTemplate);
$response = $this->mailController->sendTestMail();
$this->assertSame(Http::STATUS_OK, $response->getStatus(), $response->getData());
}