diff options
Diffstat (limited to 'app/Integration')
-rw-r--r-- | app/Integration/HipchatWebhook.php | 2 | ||||
-rw-r--r-- | app/Integration/Mailgun.php (renamed from app/Integration/MailgunWebhook.php) | 38 | ||||
-rw-r--r-- | app/Integration/Postmark.php (renamed from app/Integration/PostmarkWebhook.php) | 39 | ||||
-rw-r--r-- | app/Integration/Sendgrid.php (renamed from app/Integration/SendgridWebhook.php) | 32 | ||||
-rw-r--r-- | app/Integration/SlackWebhook.php | 2 | ||||
-rw-r--r-- | app/Integration/Smtp.php | 71 |
6 files changed, 167 insertions, 17 deletions
diff --git a/app/Integration/HipchatWebhook.php b/app/Integration/HipchatWebhook.php index 5cd01fb0..f1be0f34 100644 --- a/app/Integration/HipchatWebhook.php +++ b/app/Integration/HipchatWebhook.php @@ -89,7 +89,7 @@ class HipchatWebhook extends \Core\Base $params['room_token'] ); - $this->httpClient->post($url, $payload); + $this->httpClient->postJson($url, $payload); } } } diff --git a/app/Integration/MailgunWebhook.php b/app/Integration/Mailgun.php index 50d96a4a..1451b211 100644 --- a/app/Integration/MailgunWebhook.php +++ b/app/Integration/Mailgun.php @@ -6,21 +6,47 @@ use HTML_To_Markdown; use Core\Tool; /** - * Mailgun Webhook + * Mailgun Integration * * @package integration * @author Frederic Guillot */ -class MailgunWebhook extends \Core\Base +class Mailgun extends \Core\Base { /** + * Send a HTML email + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + */ + public function sendEmail($email, $name, $subject, $html, $author) + { + $headers = array( + 'Authorization: Basic '.base64_encode('api:'.MAILGUN_API_TOKEN) + ); + + $payload = array( + 'from' => sprintf('%s <%s>', $author, MAIL_FROM), + 'to' => sprintf('%s <%s>', $name, $email), + 'subject' => $subject, + 'html' => $html, + ); + + $this->httpClient->postForm('https://api.mailgun.net/v3/'.MAILGUN_DOMAIN.'/messages', $payload, $headers); + } + + /** * Parse incoming email * * @access public * @param array $payload Incoming email * @return boolean */ - public function parsePayload(array $payload) + public function receiveEmail(array $payload) { if (empty($payload['sender']) || empty($payload['subject']) || empty($payload['recipient'])) { return false; @@ -30,7 +56,7 @@ class MailgunWebhook extends \Core\Base $user = $this->user->getByEmail($payload['sender']); if (empty($user)) { - $this->container['logger']->debug('MailgunWebhook: ignored => user not found'); + $this->container['logger']->debug('Mailgun: ignored => user not found'); return false; } @@ -38,13 +64,13 @@ class MailgunWebhook extends \Core\Base $project = $this->project->getByIdentifier(Tool::getMailboxHash($payload['recipient'])); if (empty($project)) { - $this->container['logger']->debug('MailgunWebhook: ignored => project not found'); + $this->container['logger']->debug('Mailgun: ignored => project not found'); return false; } // The user must be member of the project if (! $this->projectPermission->isMember($project['id'], $user['id'])) { - $this->container['logger']->debug('MailgunWebhook: ignored => user is not member of the project'); + $this->container['logger']->debug('Mailgun: ignored => user is not member of the project'); return false; } diff --git a/app/Integration/PostmarkWebhook.php b/app/Integration/Postmark.php index 9051e5f7..dbb70aee 100644 --- a/app/Integration/PostmarkWebhook.php +++ b/app/Integration/Postmark.php @@ -5,21 +5,48 @@ namespace Integration; use HTML_To_Markdown; /** - * Postmark Webhook + * Postmark integration * * @package integration * @author Frederic Guillot */ -class PostmarkWebhook extends \Core\Base +class Postmark extends \Core\Base { /** + * Send a HTML email + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + */ + public function sendEmail($email, $name, $subject, $html, $author) + { + $headers = array( + 'Accept: application/json', + 'X-Postmark-Server-Token: '.POSTMARK_API_TOKEN, + ); + + $payload = array( + 'From' => sprintf('%s <%s>', $author, MAIL_FROM), + 'To' => sprintf('%s <%s>', $name, $email), + 'Subject' => $subject, + 'HtmlBody' => $html, + ); + + $this->httpClient->postJson('https://api.postmarkapp.com/email', $payload, $headers); + } + + /** * Parse incoming email * * @access public * @param array $payload Incoming email * @return boolean */ - public function parsePayload(array $payload) + public function receiveEmail(array $payload) { if (empty($payload['From']) || empty($payload['Subject']) || empty($payload['MailboxHash'])) { return false; @@ -29,7 +56,7 @@ class PostmarkWebhook extends \Core\Base $user = $this->user->getByEmail($payload['From']); if (empty($user)) { - $this->container['logger']->debug('PostmarkWebhook: ignored => user not found'); + $this->container['logger']->debug('Postmark: ignored => user not found'); return false; } @@ -37,13 +64,13 @@ class PostmarkWebhook extends \Core\Base $project = $this->project->getByIdentifier($payload['MailboxHash']); if (empty($project)) { - $this->container['logger']->debug('PostmarkWebhook: ignored => project not found'); + $this->container['logger']->debug('Postmark: ignored => project not found'); return false; } // The user must be member of the project if (! $this->projectPermission->isMember($project['id'], $user['id'])) { - $this->container['logger']->debug('PostmarkWebhook: ignored => user is not member of the project'); + $this->container['logger']->debug('Postmark: ignored => user is not member of the project'); return false; } diff --git a/app/Integration/SendgridWebhook.php b/app/Integration/Sendgrid.php index 9125f00b..902749f6 100644 --- a/app/Integration/SendgridWebhook.php +++ b/app/Integration/Sendgrid.php @@ -6,21 +6,47 @@ use HTML_To_Markdown; use Core\Tool; /** - * Sendgrid Webhook + * Sendgrid Integration * * @package integration * @author Frederic Guillot */ -class SendgridWebhook extends \Core\Base +class Sendgrid extends \Core\Base { /** + * Send a HTML email + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + */ + public function sendEmail($email, $name, $subject, $html, $author) + { + $payload = array( + 'api_user' => SENDGRID_API_USER, + 'api_key' => SENDGRID_API_KEY, + 'to' => $email, + 'toname' => $name, + 'from' => MAIL_FROM, + 'fromname' => $author, + 'html' => $html, + 'subject' => $subject, + ); + + $this->httpClient->postForm('https://api.sendgrid.com/api/mail.send.json', $payload); + } + + /** * Parse incoming email * * @access public * @param array $payload Incoming email * @return boolean */ - public function parsePayload(array $payload) + public function receiveEmail(array $payload) { if (empty($payload['envelope']) || empty($payload['subject'])) { return false; diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php index 8be33496..975ea21f 100644 --- a/app/Integration/SlackWebhook.php +++ b/app/Integration/SlackWebhook.php @@ -69,7 +69,7 @@ class SlackWebhook extends \Core\Base $payload['text'] .= '|'.t('view the task on Kanboard').'>'; } - $this->httpClient->post($this->getWebhookUrl($project_id), $payload); + $this->httpClient->postJson($this->getWebhookUrl($project_id), $payload); } } } diff --git a/app/Integration/Smtp.php b/app/Integration/Smtp.php new file mode 100644 index 00000000..ad2f30f8 --- /dev/null +++ b/app/Integration/Smtp.php @@ -0,0 +1,71 @@ +<?php + +namespace Integration; + +use Swift_Message; +use Swift_Mailer; +use Swift_MailTransport; +use Swift_SendmailTransport; +use Swift_SmtpTransport; +use Swift_TransportException; + +/** + * Smtp + * + * @package integration + * @author Frederic Guillot + */ +class Smtp extends \Core\Base +{ + /** + * Send a HTML email + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + */ + public function sendEmail($email, $name, $subject, $html, $author) + { + try { + + $message = Swift_Message::newInstance() + ->setSubject($subject) + ->setFrom(array(MAIL_FROM => $author)) + ->setBody($html, 'text/html') + ->setTo(array($email => $name)); + + Swift_Mailer::newInstance($this->getTransport())->send($message); + } + catch (Swift_TransportException $e) { + $this->container['logger']->error($e->getMessage()); + } + } + + /** + * Get SwiftMailer transport + * + * @access private + * @return \Swift_Transport + */ + private function getTransport() + { + switch (MAIL_TRANSPORT) { + case 'smtp': + $transport = Swift_SmtpTransport::newInstance(MAIL_SMTP_HOSTNAME, MAIL_SMTP_PORT); + $transport->setUsername(MAIL_SMTP_USERNAME); + $transport->setPassword(MAIL_SMTP_PASSWORD); + $transport->setEncryption(MAIL_SMTP_ENCRYPTION); + break; + case 'sendmail': + $transport = Swift_SendmailTransport::newInstance(MAIL_SENDMAIL_COMMAND); + break; + default: + $transport = Swift_MailTransport::newInstance(); + } + + return $transport; + } +} |