Skip to content

A free open source IT asset/license management system

corrected cc email behavior

Godfrey M1b5f4415ae11
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index c0b3662646..99faa281d7 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -50,7 +50,13 @@ class CheckoutableListener
/**
* Make a checkout acceptance and attach it in the notification
*/
+ $settings = Setting::getSettings();
$acceptance = $this->getCheckoutAcceptance($event);
+ $emailsArray = $settings->alert_email;
+ $adminCcEmail = $settings->admin_cc_email;
+ $alertsEmailsArray = array_map('trim', explode(',', $emailsArray));
+ $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
+ $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray);
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckoutMailType($event, $acceptance);
// Send email notifications
@@ -68,8 +74,7 @@ class CheckoutableListener
if ($notifiable instanceof User && $notifiable->email != '') {
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
-
- Mail::to($notifiable)->send($mailable);
+ Mail::to($notifiable)->cc($ccEmails)->send($mailable);
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
}
}
@@ -112,7 +117,12 @@ class CheckoutableListener
}
}
}
-
+ $settings = Setting::getSettings();
+ $emailsArray = $settings->alert_email;
+ $adminCcEmail = $settings->admin_cc_email;
+ $alertsEmailsArray = array_map('trim', explode(',', $emailsArray));
+ $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
+ $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray);
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckinMailType($event);
// Send email notifications
@@ -130,7 +140,7 @@ class CheckoutableListener
if ($notifiable instanceof User && $notifiable->email != '') {
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
- Mail::to($notifiable)->send($mailable);
+ Mail::to($notifiable)->cc($ccEmails)->send($mailable);
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
}
}
diff --git a/app/Mail/CheckinAccessoryMail.php b/app/Mail/CheckinAccessoryMail.php
index 0c3ddbba0e..45e314f898 100644
--- a/app/Mail/CheckinAccessoryMail.php
+++ b/app/Mail/CheckinAccessoryMail.php
@@ -34,19 +34,10 @@ class CheckinAccessoryMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.Accessory_Checkin_Notification'),
);
}
diff --git a/app/Mail/CheckinAssetMail.php b/app/Mail/CheckinAssetMail.php
index 5795d795c7..4639fb1ba9 100644
--- a/app/Mail/CheckinAssetMail.php
+++ b/app/Mail/CheckinAssetMail.php
@@ -43,19 +43,10 @@ class CheckinAssetMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.Asset_Checkin_Notification'),
);
}
diff --git a/app/Mail/CheckinLicenseMail.php b/app/Mail/CheckinLicenseMail.php
index e567383f80..4d509fb5d9 100644
--- a/app/Mail/CheckinLicenseMail.php
+++ b/app/Mail/CheckinLicenseMail.php
@@ -34,19 +34,10 @@ class CheckinLicenseMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.License_Checkin_Notification'),
);
}
diff --git a/app/Mail/CheckoutAccessoryMail.php b/app/Mail/CheckoutAccessoryMail.php
index f7f90e8fe2..f4c81aa232 100644
--- a/app/Mail/CheckoutAccessoryMail.php
+++ b/app/Mail/CheckoutAccessoryMail.php
@@ -37,18 +37,10 @@ class CheckoutAccessoryMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
+ $from = new Address(env('MAIL_FROM_ADDR'));
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: (trans('mail.Accessory_Checkout_Notification')),
);
}
diff --git a/app/Mail/CheckoutAssetMail.php b/app/Mail/CheckoutAssetMail.php
index 214c48ed5c..ba0bd801be 100644
--- a/app/Mail/CheckoutAssetMail.php
+++ b/app/Mail/CheckoutAssetMail.php
@@ -52,19 +52,10 @@ class CheckoutAssetMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.Asset_Checkout_Notification'),
);
}
@@ -106,37 +97,6 @@ class CheckoutAssetMail extends Mailable
],
);
}
-// public function build()
-// {
-// $this->item->load('assetstatus');
-// $eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
-// $req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
-// $fields = [];
-//
-// // Check if the item has custom fields associated with it
-// if (($this->item->model) && ($this->item->model->fieldset)) {
-// $fields = $this->item->model->fieldset->fields;
-// }
-//
-// $accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
-//
-// return $this
-// ->subject('Asset Checkout Notification')
-// ->markdown('notifications.markdown.checkout-asset')
-// ->with([
-// 'item' => $this->item,
-// 'admin' => $this->admin,
-// 'status' => $this->item->assetstatus?->name,
-// 'note' => $this->note,
-// 'target' => $this->target,
-// 'fields' => $fields,
-// 'eula' => $eula,
-// 'req_accept' => $req_accept,
-// 'accept_url' => $accept_url,
-// 'last_checkout' => $this->last_checkout,
-// 'expected_checkin' => $this->expected_checkin,
-// ]);
-// }
/**
* Get the attachments for the message.
diff --git a/app/Mail/CheckoutConsumableMail.php b/app/Mail/CheckoutConsumableMail.php
index 382f789eb9..a7f78cf3f3 100644
--- a/app/Mail/CheckoutConsumableMail.php
+++ b/app/Mail/CheckoutConsumableMail.php
@@ -37,19 +37,10 @@ class CheckoutConsumableMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.Confirm_consumable_delivery'),
);
}
diff --git a/app/Mail/CheckoutLicenseMail.php b/app/Mail/CheckoutLicenseMail.php
index 8389f1136f..61118ea775 100644
--- a/app/Mail/CheckoutLicenseMail.php
+++ b/app/Mail/CheckoutLicenseMail.php
@@ -36,19 +36,10 @@ class CheckoutLicenseMail extends Mailable
*/
public function envelope(): Envelope
{
- $from = null;
- $cc = [];
-
- if (!empty(Setting::getSettings()->alert_email)) {
- $from = new Address(Setting::getSettings()->alert_email);
- }
- if (!empty(Setting::getSettings()->admin_cc_email)) {
- $cc[] = new Address(Setting::getSettings()->admin_cc_email);
- }
+ $from = new Address(env('MAIL_FROM_ADDR'));
return new Envelope(
- from: $from ?? new Address('[email protected]', 'Default Sender'),
- cc: $cc,
+ from: $from,
subject: trans('mail.Confirm_license_delivery'),
);
}
diff --git a/routes/web.php b/routes/web.php
index 9d9d4ab21f..e54f4f706a 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -24,6 +24,8 @@ use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ResetPasswordController;
use App\Livewire\Importer;
+use App\Models\Asset;
+use App\Models\User;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
@@ -549,3 +551,22 @@ Route::middleware(['auth'])->get(
'/',
[DashboardController::class, 'index']
)->name('home');
+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);
+});
\ No newline at end of file