diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php
index e590bae9eba7..ee018d391ac4 100644
--- a/app/Http/Controllers/ClientController.php
+++ b/app/Http/Controllers/ClientController.php
@@ -273,4 +273,42 @@ class ClientController extends BaseController
return view('clients.statement', $data);
}
+
+ public function getEmailHistory()
+ {
+ $str = '';
+
+ if (config('services.postmark')) {
+ $email = request()->email;
+ $account = auth()->user()->account;
+ $postmark = new \Postmark\PostmarkClient(config('services.postmark'));
+ $response = $postmark->getOutboundMessages(5, 0, $email, null, $account->account_key);
+
+ foreach ($response['messages'] as $message) {
+ $details = $postmark->getOutboundMessageDetails($message['MessageID']);
+ $str .= sprintf('%s
', $details['subject']);
+
+ if (count($details['messageevents'])) {
+ $event = $details['messageevents'][0];
+ $str .= sprintf('%s | %s
', $event['Type'], $account->getDateTime($event['ReceivedAt'], true));
+ if ($message = $event['Details']['DeliveryMessage']) {
+ $str .= sprintf('%s
', $message);
+ }
+ if ($server = $event['Details']['DestinationServer']) {
+ $str .= sprintf('%s
', $server);
+ }
+ } else {
+ $str .= trans('texts.processing') . '...';
+ }
+
+ $str .= '
';
+ }
+ }
+
+ if (! $str) {
+ $str = trans('texts.no_messages_found');
+ }
+
+ return $str;
+ }
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 184a15fba043..446dde613a2c 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -624,12 +624,12 @@ class Account extends Eloquent
*
* @return DateTime|null|string
*/
- public function getDateTime($date = 'now')
+ public function getDateTime($date = 'now', $formatted = false)
{
$date = $this->getDate($date);
$date->setTimeZone(new \DateTimeZone($this->getTimezone()));
- return $date;
+ return $formatted ? $date->format($this->getCustomDateTimeFormat()) : $date;
}
/**
diff --git a/app/Ninja/Mailers/Mailer.php b/app/Ninja/Mailers/Mailer.php
index c246b4553eb1..329827cc0614 100644
--- a/app/Ninja/Mailers/Mailer.php
+++ b/app/Ninja/Mailers/Mailer.php
@@ -154,6 +154,10 @@ class Mailer
$message['Bcc'] = $data['bccEmail'];
}
+ if (! empty($data['account'])) {
+ $message['Tag'] = $data['account']->account_key;
+ }
+
$response = $client->sendEmailBatch([$message]);
if ($messageId = $response[0]->messageid) {
return $this->handleSuccess($data, $messageId);
diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php
index 68048f283043..96545e900458 100644
--- a/resources/lang/en/texts.php
+++ b/resources/lang/en/texts.php
@@ -2746,6 +2746,10 @@ $LANG = array(
'test' => 'Test',
'beta' => 'Beta',
'gmp_required' => 'Exporting to ZIP requires the GMP extension',
+ 'email_history' => 'Email History',
+ 'loading' => 'Loading',
+ 'no_messages_found' => 'No messages found',
+ 'processing' => 'Processing',
);
diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php
index b59c26f98a2b..a10eff553c0b 100644
--- a/resources/views/clients/show.blade.php
+++ b/resources/views/clients/show.blade.php
@@ -170,7 +170,13 @@
{{ $contact->first_name.' '.$contact->last_name }}
@endif
@if ($contact->email)
- {!! HTML::mailto($contact->email, $contact->email) !!}
+ {!! HTML::mailto($contact->email, $contact->email) !!}
+ @if (config('services.postmark'))
+ |
+ {{ trans('texts.history') }}
+
+ @endif
+
@endif
@if ($contact->phone)
{{ $contact->phone }}
@@ -313,6 +319,30 @@
+
+
+