summaryrefslogtreecommitdiff
path: root/app/Core/Mail/Client.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-16 20:50:12 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-16 20:50:12 -0400
commitf99a3c501fd6ed7b4914b8d6e855489c2ce5b219 (patch)
tree976276d6acfff78923e4549b0ef9ea94c5e2cb0d /app/Core/Mail/Client.php
parent9c9ed02cd7ebc5dbbc99bcaed6f80988ce8a9677 (diff)
Make mail transports pluggable and move integrations to plugins
- Postmark: https://github.com/kanboard/plugin-postmark - Mailgun: https://github.com/kanboard/plugin-mailgun - Sendgrid: https://github.com/kanboard/plugin-sendgrid
Diffstat (limited to 'app/Core/Mail/Client.php')
-rw-r--r--app/Core/Mail/Client.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/app/Core/Mail/Client.php b/app/Core/Mail/Client.php
new file mode 100644
index 00000000..c7cfaab9
--- /dev/null
+++ b/app/Core/Mail/Client.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Kanboard\Core\Mail;
+
+use Pimple\Container;
+use Kanboard\Core\Base;
+
+/**
+ * Mail Client
+ *
+ * @package mail
+ * @author Frederic Guillot
+ */
+class Client extends Base
+{
+ /**
+ * Mail transport instances
+ *
+ * @access private
+ * @var \Pimple\Container
+ */
+ private $transports;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Pimple\Container $container
+ */
+ public function __construct(Container $container)
+ {
+ parent::__construct($container);
+ $this->transports = new Container;
+ }
+
+ /**
+ * Send a HTML email
+ *
+ * @access public
+ * @param string $email
+ * @param string $name
+ * @param string $subject
+ * @param string $html
+ * @return EmailClient
+ */
+ public function send($email, $name, $subject, $html)
+ {
+ $this->container['logger']->debug('Sending email to '.$email.' ('.MAIL_TRANSPORT.')');
+
+ $start_time = microtime(true);
+ $author = 'Kanboard';
+
+ if ($this->userSession->isLogged()) {
+ $author = e('%s via Kanboard', $this->user->getFullname($this->session['user']));
+ }
+
+ $this->getTransport(MAIL_TRANSPORT)->sendEmail($email, $name, $subject, $html, $author);
+
+ if (DEBUG) {
+ $this->logger->debug('Email sent in '.round(microtime(true) - $start_time, 6).' seconds');
+ }
+
+ return $this;
+ }
+
+ /**
+ * Get mail transport instance
+ *
+ * @access public
+ * @param string $transport
+ * @return EmailClientInterface
+ */
+ public function getTransport($transport)
+ {
+ return $this->transports[$transport];
+ }
+
+ /**
+ * Add a new mail transport
+ *
+ * @access public
+ * @param string $transport
+ * @param string $class
+ * @return EmailClient
+ */
+ public function setTransport($transport, $class)
+ {
+ $container = $this->container;
+
+ $this->transports[$transport] = function() use ($class, $container) {
+ return new $class($container);
+ };
+
+ return $this;
+ }
+}