Add Reply-To header to emails sent from Kanboard
This commit is contained in:
parent
b4dc602381
commit
bd0ed33179
|
|
@ -4,6 +4,7 @@ Version 1.0.40 (unreleased)
|
||||||
New features:
|
New features:
|
||||||
|
|
||||||
* Send comments by email
|
* Send comments by email
|
||||||
|
* Add Reply-To header to emails sent from Kanboard
|
||||||
* Upload Sqlite database from user interface
|
* Upload Sqlite database from user interface
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
@ -23,6 +24,7 @@ Breaking changes:
|
||||||
* Columns "default_swimlane" and "show_default_swimlane" from "projects" table are not used anymore
|
* Columns "default_swimlane" and "show_default_swimlane" from "projects" table are not used anymore
|
||||||
* Remove API method "getDefaultSwimlane()"
|
* Remove API method "getDefaultSwimlane()"
|
||||||
* Add mandatory argument "project_id" to API method "updateSwimlane()"
|
* Add mandatory argument "project_id" to API method "updateSwimlane()"
|
||||||
|
* Change interface for mail transports
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use Kanboard\Core\Base;
|
||||||
/**
|
/**
|
||||||
* Mail Client
|
* Mail Client
|
||||||
*
|
*
|
||||||
* @package mail
|
* @package Kanboard\Core\Mail
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Client extends Base
|
class Client extends Base
|
||||||
|
|
@ -38,30 +38,35 @@ class Client extends Base
|
||||||
* Send a HTML email
|
* Send a HTML email
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @return Client
|
* @return Client
|
||||||
*/
|
*/
|
||||||
public function send($email, $name, $subject, $html)
|
public function send($recipientEmail, $recipientName, $subject, $html)
|
||||||
{
|
{
|
||||||
if (! empty($email)) {
|
if (! empty($recipientEmail)) {
|
||||||
$this->queueManager->push(EmailJob::getInstance($this->container)
|
$this->queueManager->push(EmailJob::getInstance($this->container)->withParams(
|
||||||
->withParams($email, $name, $subject, $html, $this->getAuthor())
|
$recipientEmail,
|
||||||
);
|
$recipientName,
|
||||||
|
$subject,
|
||||||
|
$html,
|
||||||
|
$this->getAuthorName(),
|
||||||
|
$this->getAuthorEmail()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get email author
|
* Get author name
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAuthor()
|
public function getAuthorName()
|
||||||
{
|
{
|
||||||
$author = 'Kanboard';
|
$author = 'Kanboard';
|
||||||
|
|
||||||
|
|
@ -72,6 +77,22 @@ class Client extends Base
|
||||||
return $author;
|
return $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get author email
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAuthorEmail()
|
||||||
|
{
|
||||||
|
if ($this->userSession->isLogged()) {
|
||||||
|
$userData = $this->userSession->getAll();
|
||||||
|
return ! empty($userData['email']) ? $userData['email'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get mail transport instance
|
* Get mail transport instance
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace Kanboard\Core\Mail;
|
||||||
/**
|
/**
|
||||||
* Mail Client Interface
|
* Mail Client Interface
|
||||||
*
|
*
|
||||||
* @package mail
|
* @package Kanboard\Core\Mail
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
interface ClientInterface
|
interface ClientInterface
|
||||||
|
|
@ -14,11 +14,12 @@ interface ClientInterface
|
||||||
* Send a HTML email
|
* Send a HTML email
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param string $author
|
* @param string $authorName
|
||||||
|
* @param string $authorEmail
|
||||||
*/
|
*/
|
||||||
public function sendEmail($email, $name, $subject, $html, $author);
|
public function sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail = '');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use Kanboard\Core\Mail\ClientInterface;
|
||||||
/**
|
/**
|
||||||
* PHP Mail Handler
|
* PHP Mail Handler
|
||||||
*
|
*
|
||||||
* @package transport
|
* @package Kanboard\Core\Mail\Transport
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Mail extends Base implements ClientInterface
|
class Mail extends Base implements ClientInterface
|
||||||
|
|
@ -21,20 +21,26 @@ class Mail extends Base implements ClientInterface
|
||||||
* Send a HTML email
|
* Send a HTML email
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param string $author
|
* @param string $authorName
|
||||||
|
* @param string $authorEmail
|
||||||
*/
|
*/
|
||||||
public function sendEmail($email, $name, $subject, $html, $author)
|
public function sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail = '')
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$message = Swift_Message::newInstance()
|
$message = Swift_Message::newInstance()
|
||||||
->setSubject($subject)
|
->setSubject($subject)
|
||||||
->setFrom(array($this->helper->mail->getMailSenderAddress() => $author))
|
->setFrom($this->helper->mail->getMailSenderAddress(), $authorName)
|
||||||
->setTo(array($email => $name))
|
->setTo(array($recipientEmail => $recipientName));
|
||||||
->setBody($html, 'text/html');
|
|
||||||
|
if (! empty($authorEmail)) {
|
||||||
|
$message->setReplyTo($authorEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
$message->setBody($html, 'text/html');
|
||||||
|
|
||||||
Swift_Mailer::newInstance($this->getTransport())->send($message);
|
Swift_Mailer::newInstance($this->getTransport())->send($message);
|
||||||
} catch (Swift_TransportException $e) {
|
} catch (Swift_TransportException $e) {
|
||||||
|
|
@ -46,7 +52,7 @@ class Mail extends Base implements ClientInterface
|
||||||
* Get SwiftMailer transport
|
* Get SwiftMailer transport
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @return \Swift_Transport|\Swift_MailTransport|\Swift_SmtpTransport|\Swift_SendmailTransport
|
* @return \Swift_Transport
|
||||||
*/
|
*/
|
||||||
protected function getTransport()
|
protected function getTransport()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use Swift_SendmailTransport;
|
||||||
/**
|
/**
|
||||||
* PHP Mail Handler
|
* PHP Mail Handler
|
||||||
*
|
*
|
||||||
* @package transport
|
* @package Kanboard\Core\Mail\Transport
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Sendmail extends Mail
|
class Sendmail extends Mail
|
||||||
|
|
@ -16,7 +16,7 @@ class Sendmail extends Mail
|
||||||
* Get SwiftMailer transport
|
* Get SwiftMailer transport
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @return \Swift_Transport|\Swift_MailTransport|\Swift_SmtpTransport|\Swift_SendmailTransport
|
* @return \Swift_Transport
|
||||||
*/
|
*/
|
||||||
protected function getTransport()
|
protected function getTransport()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use Swift_SmtpTransport;
|
||||||
/**
|
/**
|
||||||
* PHP Mail Handler
|
* PHP Mail Handler
|
||||||
*
|
*
|
||||||
* @package transport
|
* @package Kanboard\Core\Mail\Transport
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Smtp extends Mail
|
class Smtp extends Mail
|
||||||
|
|
@ -16,7 +16,7 @@ class Smtp extends Mail
|
||||||
* Get SwiftMailer transport
|
* Get SwiftMailer transport
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @return \Swift_Transport|\Swift_MailTransport|\Swift_SmtpTransport|\Swift_SendmailTransport
|
* @return \Swift_Transport
|
||||||
*/
|
*/
|
||||||
protected function getTransport()
|
protected function getTransport()
|
||||||
{
|
{
|
||||||
|
|
@ -29,8 +29,8 @@ class Smtp extends Mail
|
||||||
$transport->setStreamOptions(array(
|
$transport->setStreamOptions(array(
|
||||||
'ssl' => array(
|
'ssl' => array(
|
||||||
'allow_self_signed' => true,
|
'allow_self_signed' => true,
|
||||||
'verify_peer' => false,
|
'verify_peer' => false,
|
||||||
'verify_peer_name' => false,
|
'verify_peer_name' => false,
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,17 @@ class EmailJob extends BaseJob
|
||||||
* Set job parameters
|
* Set job parameters
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param string $author
|
* @param string $authorName
|
||||||
|
* @param string $authorEmail
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function withParams($email, $name, $subject, $html, $author)
|
public function withParams($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail)
|
||||||
{
|
{
|
||||||
$this->jobParams = array($email, $name, $subject, $html, $author);
|
$this->jobParams = array($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,25 +32,24 @@ class EmailJob extends BaseJob
|
||||||
* Execute job
|
* Execute job
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param string $author
|
* @param string $authorName
|
||||||
|
* @param string $authorEmail
|
||||||
*/
|
*/
|
||||||
public function execute($email, $name, $subject, $html, $author)
|
public function execute($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail)
|
||||||
{
|
{
|
||||||
$transport = $this->helper->mail->getMailTransport();
|
$transport = $this->helper->mail->getMailTransport();
|
||||||
$this->logger->debug(__METHOD__.' Sending email to: '.$email.' using transport: '.$transport);
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
|
|
||||||
|
$this->logger->debug(__METHOD__.' Sending email to: '.$recipientEmail.' using transport: '.$transport);
|
||||||
|
|
||||||
$this->emailClient
|
$this->emailClient
|
||||||
->getTransport($transport)
|
->getTransport($transport)
|
||||||
->sendEmail($email, $name, $subject, $html, $author)
|
->sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail);
|
||||||
;
|
|
||||||
|
|
||||||
if (DEBUG) {
|
$this->logger->debug(__METHOD__.' Email sent in '.round(microtime(true) - $startTime, 6).' seconds');
|
||||||
$this->logger->debug('Email sent in '.round(microtime(true) - $startTime, 6).' seconds');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,14 @@ interface ClientInterface
|
||||||
* Send a HTML email
|
* Send a HTML email
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $email
|
* @param string $recipientEmail
|
||||||
* @param string $name
|
* @param string $recipientName
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param string $author
|
* @param string $authorName
|
||||||
|
* @param string $authorEmail
|
||||||
*/
|
*/
|
||||||
public function sendEmail($email, $name, $subject, $html, $author);
|
public function sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail = '');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue