From a27057dd6fbf59e7e88ac19494573a5415d2707e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 2 Jun 2016 20:58:34 -0400 Subject: Expose to the user interface the email sender address --- app/Core/Mail/Transport/Mail.php | 2 +- app/Helper/MailHelper.php | 17 +++++++++++++++++ app/Template/config/application.php | 3 +++ tests/units/Helper/MailHelperTest.php | 11 +++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Core/Mail/Transport/Mail.php b/app/Core/Mail/Transport/Mail.php index aff3ee20..d27925f0 100644 --- a/app/Core/Mail/Transport/Mail.php +++ b/app/Core/Mail/Transport/Mail.php @@ -32,7 +32,7 @@ class Mail extends Base implements ClientInterface try { $message = Swift_Message::newInstance() ->setSubject($subject) - ->setFrom(array(MAIL_FROM => $author)) + ->setFrom(array($this->helper->mail->getMailSenderAddress() => $author)) ->setBody($html, 'text/html') ->setTo(array($email => $name)); diff --git a/app/Helper/MailHelper.php b/app/Helper/MailHelper.php index 6c7eeff0..12e7f05f 100644 --- a/app/Helper/MailHelper.php +++ b/app/Helper/MailHelper.php @@ -45,4 +45,21 @@ class MailHelper extends Base return $subject; } + + /** + * Get mail sender address + * + * @access public + * @return string + */ + public function getMailSenderAddress() + { + $email = $this->configModel->get('mail_sender_address'); + + if (!empty($email)) { + return $email; + } + + return MAIL_FROM; + } } diff --git a/app/Template/config/application.php b/app/Template/config/application.php index 0f842f6e..b66d0633 100644 --- a/app/Template/config/application.php +++ b/app/Template/config/application.php @@ -9,6 +9,9 @@ form->text('application_url', $values, $errors, array('placeholder="http://example.kanboard.net/"')) ?>

+ form->label(t('Email sender address'), 'mail_sender_address') ?> + form->text('mail_sender_address', $values, $errors, array('placeholder="'.MAIL_FROM.'"')) ?> + form->label(t('Language'), 'application_language') ?> form->select('application_language', $languages, $values, $errors) ?> diff --git a/tests/units/Helper/MailHelperTest.php b/tests/units/Helper/MailHelperTest.php index 9975dd29..b2d4ba6e 100644 --- a/tests/units/Helper/MailHelperTest.php +++ b/tests/units/Helper/MailHelperTest.php @@ -21,4 +21,15 @@ class MailHelperTest extends Base $this->assertEquals('Test', $helper->filterSubject('RE: Test')); $this->assertEquals('Test', $helper->filterSubject('FW: Test')); } + + public function testGetSenderAddress() + { + $helper = new MailHelper($this->container); + $this->assertEquals('notifications@kanboard.local', $helper->getMailSenderAddress()); + + $this->container['configModel']->save(array('mail_sender_address' => 'me@here')); + $this->container['memoryCache']->flush(); + + $this->assertEquals('me@here', $helper->getMailSenderAddress()); + } } -- cgit v1.2.3