Skip to content

Commit

Permalink
update config file with optional separate webhook prefix and mailgun …
Browse files Browse the repository at this point in the history
…event config
  • Loading branch information
dmcbrn committed May 10, 2022
2 parents 2ce4415 + 34fce30 commit 9e26f60
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion config/email_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
return [
'disk' => env('EMAIL_LOG_ATTACHMENT_DISK','email_log_attachments'),
'access_middleware' => env('EMAIL_LOG_ACCESS_MIDDLEWARE',null),
'routes_prefix' => env('EMAIL_LOG_ROUTES_PREFIX',''), //when changing prefix please be sure to update the webhook's URLs also
'routes_prefix' => env('EMAIL_LOG_ROUTES_PREFIX',''),
'routes_webhook_prefix' => env('EMAIL_LOG_ROUTES_WEBHOOK_PREFIX', env('EMAIL_LOG_ROUTES_PREFIX','')),
'mailgun' => [
'secret' => env('MAILGUN_SECRET', null),
'filter_unknown_emails' => env('EMAIL_LOG_MAILGUN_FILTER_UNKNOWN_EMAILS', true),
],
];
10 changes: 6 additions & 4 deletions src/Events/MailgunEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MailgunEvent extends Event
public function verify(Request $request)
{
//get needed data
$apiKey = env('MAILGUN_SECRET', null);
$apiKey = config('email_log.mailgun.secret', null);
$token = $request->signature['token'];
$timestamp = $request->signature['timestamp'];
$signature = $request->signature['signature'];
Expand All @@ -26,13 +26,15 @@ public function verify(Request $request)
public function saveEvent(Request $request)
{
//get email
$email = $this->getEmail(strtok($request->{'event-data'}['message']['headers']['message-id'], '@'));
if(!$email)
$mail_id_str = strtok($request->{'event-data'}['message']['headers']['message-id'], '@');
$email = $this->getEmail($mail_id_str);
if(!$email && config('email_log.email.filter_unknown_emails')) {
return response('Error: no E-mail found', 200)->header('Content-Type', 'text/plain');
}

//save event
EmailLogEvent::create([
'messageId' => $email->messageId,
'messageId' => $mail_id_str,
'event' => $request->{'event-data'}['event'],
'data' => json_encode($request->all()),
]);
Expand Down
9 changes: 9 additions & 0 deletions views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
<li>Headers: {{ $email->headers }}</li>
<li>Message ID: {{ $email->messageId }}</li>
<li>Mail Driver: {{ $email->mail_driver }}</li>
<li>Events:
@if(count($email->events ?? []) > 0)
<ul>
@foreach($email->events as $event)
<li><strong>{{ $event->event }}</strong> {{ $event->created_at }}</li>
@endforeach
</ul>
@endif
</li>
</ul>

<a href="{{ route('email-log') }}">Back to All</a>
Expand Down

0 comments on commit 9e26f60

Please sign in to comment.