]> source.dussan.org Git - nextcloud-server.git/commitdiff
Beautify test email 4379/head
authorLukas Reschke <lukas@statuscode.ch>
Tue, 18 Apr 2017 19:30:31 +0000 (21:30 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 18 Apr 2017 21:18:00 +0000 (16:18 -0500)
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
settings/Controller/MailSettingsController.php
tests/Settings/Controller/MailSettingsControllerTest.php

index f0fd7a52f0b9e0e8522b102ae245f3c832400c7e..ed7420596654254f721c96ff1c8c230def0cdb47 100644 (file)
@@ -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'));
index c8f9e476801df684536eae8cb8b75f9805a1c2cf..79fe0683cc59b7e0113a4712d70a8e147a9c5c4d 100644 (file)
@@ -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());
        }