Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Add support for Reply-To header
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Feb 19, 2017
1 parent e3c464f commit 82661a5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
17 changes: 11 additions & 6 deletions EmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,30 @@ class EmailHandler extends Base implements ClientInterface
* Send a HTML email
*
* @access public
* @param string $email
* @param string $name
* @param string $recipientEmail
* @param string $recipientName
* @param string $subject
* @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 = '')
{
$headers = array(
'Authorization: Basic '.base64_encode('api:'.$this->getApiToken())
);

$payload = array(
'from' => sprintf('%s <%s>', $author, $this->helper->mail->getMailSenderAddress()),
'to' => sprintf('%s <%s>', $name, $email),
'from' => sprintf('%s <%s>', $authorName, $this->helper->mail->getMailSenderAddress()),
'to' => sprintf('%s <%s>', $recipientName, $recipientEmail),
'subject' => $subject,
'html' => $html,
);

if (! empty($authorEmail)) {
$payload['h:Reply-To'] = $authorEmail;
}

$this->httpClient->postFormAsync('https://api.mailgun.net/v3/'.$this->getDomain().'/messages', $payload, $headers);
}

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
plugin=Mailgun

all:
@ echo "Build archive for plugin ${plugin} version=${version}"
@ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
4 changes: 2 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.0.7';
return '1.0.8';
}

public function getPluginHomepage()
Expand All @@ -49,6 +49,6 @@ public function getPluginHomepage()

public function getCompatibleVersion()
{
return '>=1.0.39';
return '>=1.0.40';
}
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Author
Requirements
------------

- Kanboard >= 1.0.39
- Kanboard >= 1.0.40
- Mailgun API credentials

Installation
Expand Down Expand Up @@ -111,6 +111,10 @@ Notes
Changes
-------

### Version 1.0.8

- Add support for Reply-To header

### Version 1.0.7

- Add original email body as attachment
Expand Down
23 changes: 23 additions & 0 deletions Test/EmailHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ public function testSendEmail()
$handler->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob');
}

public function testSendEmailWithAuthorEmail()
{
$handler = new EmailHandler($this->container);

$headers = array(
'Authorization: Basic '.base64_encode('api:my token')
);

$this->container['configModel']
->save(array('mailgun_api_token' => 'my token', 'mailgun_domain' => 'my_domain'));

$this->container['httpClient']
->expects($this->once())
->method('postFormAsync')
->with(
'https://api.mailgun.net/v3/my_domain/messages',
$this->contains('bob@localhost'),
$headers
);

$handler->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob', 'bob@localhost');
}

public function testHandlePayload()
{
$emailHandler = new EmailHandler($this->container);
Expand Down

0 comments on commit 82661a5

Please sign in to comment.