email comes through, no picture and html markup appear though.

This commit is contained in:
Godfrey M 2024-10-16 12:21:33 -07:00
parent 9f06a0e441
commit 3ab2521cb0
5 changed files with 100 additions and 99 deletions

View file

@ -338,4 +338,5 @@ class AcceptanceController extends Controller
return redirect()->to('account/accept')->with('success', $return_msg); return redirect()->to('account/accept')->with('success', $return_msg);
} }
} }

View file

@ -51,8 +51,8 @@ class CheckoutableListener
$event->checkoutable, $event->checkoutable,
$event->checkedOutTo, $event->checkedOutTo,
$event->checkedOutBy, $event->checkedOutBy,
$event->note,
$acceptance, $acceptance,
$event->note
)); ));
// Send email notifications // Send email notifications
@ -61,18 +61,18 @@ class CheckoutableListener
$mailable->locale($event->checkedOutTo->locale); $mailable->locale($event->checkedOutTo->locale);
} }
Mail::to($notifiable)->send($mailable); Mail::to($notifiable)->send($mailable);
\Log::info('Sending email, Locale: ' .($event->checkedOutTo->locale ?? 'default')); Log::info('Sending email, Locale: ' .($event->checkedOutTo->locale ?? 'default'));
// Send Webhook notification // Send Webhook notification
if ($this->shouldSendWebhookNotification()) { // if ($this->shouldSendWebhookNotification()) {
// Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint // // Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint
if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') { // if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
Notification::route('slack', Setting::getSettings()->webhook_endpoint) // Notification::route('slack', Setting::getSettings()->webhook_endpoint)
->notify($this->getCheckoutNotification($event, $acceptance)); // ->notify($this->getCheckoutNotification($event, $acceptance));
} else { // } else {
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) // Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
->notify($this->getCheckoutNotification($event, $acceptance)); // ->notify($this->getCheckoutNotification($event, $acceptance));
} // }
} // }
} catch (ClientException $e) { } catch (ClientException $e) {
Log::debug("Exception caught during checkout notification: " . $e->getMessage()); Log::debug("Exception caught during checkout notification: " . $e->getMessage());
} catch (Exception $e) { } catch (Exception $e) {
@ -113,7 +113,6 @@ class CheckoutableListener
$event->checkedOutTo, $event->checkedOutTo,
$event->checkedOutBy, $event->checkedOutBy,
$event->note, $event->note,
null,
)); ));
// Send email notifications // Send email notifications

View file

@ -32,28 +32,7 @@ class CheckoutAssetNotification extends Notification
*/ */
public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $acceptance, $note) public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
{ {
$this->item = $asset;
$this->admin = $checkedOutBy;
$this->note = $note;
$this->target = $checkedOutTo;
$this->acceptance = $acceptance;
$this->settings = Setting::getSettings();
$this->last_checkout = '';
$this->expected_checkin = '';
if ($this->item->last_checkout) {
$this->last_checkout = Helper::getFormattedDateObject($this->item->last_checkout, 'date',
false);
}
if ($this->item->expected_checkin) {
$this->expected_checkin = Helper::getFormattedDateObject($this->item->expected_checkin, 'date',
false);
}
} }
/** /**
* Get the notification's delivery channels. * Get the notification's delivery channels.
* *

View file

@ -1,76 +1,76 @@
@component('mail::message') @component('mail::message')
# {{ trans('mail.hello') }} {{ $target->present()->fullName() }}, # {{ trans('mail.hello') }} {{ $target->present()->fullName() }},
{{ trans('mail.new_item_checked') }} {{ trans('mail.new_item_checked') }}
@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl()) @if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
<center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center> <center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center>
@endif @endif
@component('mail::table') @component('mail::table')
| | | | | |
| ------------- | ------------- | | ------------- | ------------- |
@if ((isset($item->name)) && ($item->name!='')) @if ((isset($item->name)) && ($item->name!=''))
| **{{ trans('mail.asset_name') }}** | {{ $item->name }} | | **{{ trans('mail.asset_name') }}** | {{ $item->name }} |
@endif @endif
@if (($item->name!=$item->asset_tag)) @if (($item->name!=$item->asset_tag))
| **{{ trans('mail.asset_tag') }}** | {{ $item->asset_tag }} | | **{{ trans('mail.asset_tag') }}** | {{ $item->asset_tag }} |
@endif @endif
@if (isset($item->manufacturer)) @if (isset($item->manufacturer))
| **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} | | **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} |
@endif @endif
@if (isset($item->model)) @if (isset($item->model))
| **{{ trans('general.asset_model') }}** | {{ $item->model->name }} | | **{{ trans('general.asset_model') }}** | {{ $item->model->name }} |
@endif @endif
@if ((isset($item->model->model_number)) && ($item->model->name!=$item->model->model_number)) @if ((isset($item->model->model_number)) && ($item->model->name!=$item->model->model_number))
| **{{ trans('general.model_no') }}** | {{ $item->model->model_number }} | | **{{ trans('general.model_no') }}** | {{ $item->model->model_number }} |
@endif @endif
@if (isset($item->serial)) @if (isset($item->serial))
| **{{ trans('mail.serial') }}** | {{ $item->serial }} | | **{{ trans('mail.serial') }}** | {{ $item->serial }} |
@endif @endif
@if (isset($last_checkout)) @if (isset($last_checkout))
| **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} |
@endif @endif
@if (isset($status)) @if (isset($status))
| **{{ trans('general.status') }}** | {{ $status }} | | **{{ trans('general.status') }}** | {{ $status }} |
@endif @endif
@if ((isset($expected_checkin)) && ($expected_checkin!='')) @if ((isset($expected_checkin)) && ($expected_checkin!=''))
| **{{ trans('mail.expecting_checkin_date') }}** | {{ $expected_checkin }} | | **{{ trans('mail.expecting_checkin_date') }}** | {{ $expected_checkin }} |
@endif @endif
@foreach($fields as $field) @foreach($fields as $field)
@if (($item->{ $field->db_column_name() }!='') && ($field->show_in_email) && ($field->field_encrypted=='0')) @if (($item->{ $field->db_column_name() }!='') && ($field->show_in_email) && ($field->field_encrypted=='0'))
| **{{ $field->name }}** | {{ $item->{ $field->db_column_name() } }} | | **{{ $field->name }}** | {{ $item->{ $field->db_column_name() } }} |
@endif @endif
@endforeach @endforeach
@if ($admin) @if ($admin)
| **{{ trans('general.administrator') }}** | {{ $admin->present()->fullName() }} | | **{{ trans('general.administrator') }}** | {{ $admin->present()->fullName() }} |
@endif @endif
@if ($note) @if ($note)
| **{{ trans('mail.additional_notes') }}** | {{ $note }} | | **{{ trans('mail.additional_notes') }}** | {{ $note }} |
@endif @endif
@endcomponent @endcomponent
@if (($req_accept == 1) && ($eula!='')) @if (($req_accept == 1) && ($eula!=''))
{{ trans('mail.read_the_terms_and_click') }} {{ trans('mail.read_the_terms_and_click') }}
@elseif (($req_accept == 1) && ($eula=='')) @elseif (($req_accept == 1) && ($eula==''))
{{ trans('mail.click_on_the_link_asset') }} {{ trans('mail.click_on_the_link_asset') }}
@elseif (($req_accept == 0) && ($eula!='')) @elseif (($req_accept == 0) && ($eula!=''))
{{ trans('mail.read_the_terms') }} {{ trans('mail.read_the_terms') }}
@endif @endif
@if ($eula) @if ($eula)
@component('mail::panel') @component('mail::panel')
{!! $eula !!} {!! $eula !!}
@endcomponent @endcomponent
@endif @endif
@if ($req_accept == 1) @if ($req_accept == 1)
**[ {{ trans('mail.i_have_read') }}]({{ $accept_url }})** **[ {{ trans('mail.i_have_read') }}]({{ $accept_url }})**
@endif @endif
{{ trans('mail.best_regards') }} {{ trans('mail.best_regards') }}
{{ $snipeSettings->site_name }} {{ $snipeSettings->site_name }}
@endcomponent @endcomponent

View file

@ -24,6 +24,8 @@ use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\ForgotPasswordController; use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ResetPasswordController; use App\Http\Controllers\Auth\ResetPasswordController;
use App\Livewire\Importer; use App\Livewire\Importer;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -53,6 +55,26 @@ Route::group(['middleware' => 'auth'], function () {
/* /*
* Locations * Locations
*/ */
Route::get('/test-email', function() {
$item = Asset::find(1); // Load some test data
$admin = User::find(1);
$target = User::find(2);
$acceptance = null; // Simulate acceptance data
$note = 'Test note';
$fields = [];
if (($item->model) && ($item->model->fieldset)) {
$fields = $item->model->fieldset->fields;
}
return new \App\Mail\CheckoutAssetMail(
$item,
$admin,
$target,
$acceptance,
$note);
});
Route::group(['prefix' => 'locations', 'middleware' => ['auth']], function () { Route::group(['prefix' => 'locations', 'middleware' => ['auth']], function () {