Skip to content

A free open source IT asset/license management system

adds expiring asset and license mail

Godfrey Mfb7bec4be417
diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php
index 025ba2ce23..20dd6c6742 100644
--- a/app/Console/Commands/SendExpirationAlerts.php
+++ b/app/Console/Commands/SendExpirationAlerts.php
@@ -2,6 +2,8 @@
namespace App\Console\Commands;
+use App\Mail\ExpiringAssetsMail;
+use App\Mail\ExpiringLicenseMail;
use App\Models\Asset;
use App\Models\License;
use App\Models\Recipients\AlertRecipient;
@@ -9,6 +11,7 @@ use App\Models\Setting;
use App\Notifications\ExpiringAssetsNotification;
use App\Notifications\ExpiringLicenseNotification;
use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Mail;
class SendExpirationAlerts extends Command
{
@@ -47,22 +50,22 @@ class SendExpirationAlerts extends Command
if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) {
// Send a rollup to the admin, if settings dictate
- $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
- return new AlertRecipient($item);
- });
+ $recipients = collect(explode(',', $settings->alert_email))
+ ->map(fn($item) => trim($item)) // Trim each email
+ ->all();
// Expiring Assets
$assets = Asset::getExpiringWarrantee($threshold);
if ($assets->count() > 0) {
$this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold]));
- \Notification::send($recipients, new ExpiringAssetsNotification($assets, $threshold));
+ Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $threshold));
}
// Expiring licenses
$licenses = License::getExpiringLicenses($threshold);
if ($licenses->count() > 0) {
$this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold]));
- \Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold));
+ Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $threshold));
}
} else {
if ($settings->alert_email == '') {
diff --git a/app/Mail/ExpiringAssetsMail.php b/app/Mail/ExpiringAssetsMail.php
new file mode 100644
index 0000000000..13d322f060
--- /dev/null
+++ b/app/Mail/ExpiringAssetsMail.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Mail;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Address;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+
+class ExpiringAssetsMail extends Mailable
+{
+ use Queueable, SerializesModels;
+
+ /**
+ * Create a new message instance.
+ */
+ public function __construct($params, $threshold)
+ {
+ $this->assets = $params;
+ $this->threshold = $threshold;
+ }
+
+ /**
+ * Get the message envelope.
+ */
+ public function envelope(): Envelope
+ {
+ $from = new Address(config('mail.from.address'), config('mail.from.name'));
+
+ return new Envelope(
+ from: $from,
+ subject: trans('mail.Expiring_Assets_Report'),
+ );
+ }
+
+ /**
+ * Get the message content definition.
+ */
+ public function content(): Content
+ {
+ return new Content(
+ markdown: 'notifications.markdown.report-expiring-assets',
+ with: [
+ 'assets' => $this->assets,
+ 'threshold' => $this->threshold,
+ ]
+ );
+ }
+
+ /**
+ * Get the attachments for the message.
+ *
+ * @return array<int, \Illuminate\Mail\Mailables\Attachment>
+ */
+ public function attachments(): array
+ {
+ return [];
+ }
+}
diff --git a/app/Mail/ExpiringLicenseMail.php b/app/Mail/ExpiringLicenseMail.php
new file mode 100644
index 0000000000..77d94df637
--- /dev/null
+++ b/app/Mail/ExpiringLicenseMail.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Mail;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Address;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+
+class ExpiringLicenseMail extends Mailable
+{
+ use Queueable, SerializesModels;
+
+ /**
+ * Create a new message instance.
+ */
+ public function __construct($params, $threshold)
+ {
+ $this->licenses = $params;
+ $this->threshold = $threshold;
+ }
+
+ /**
+ * Get the message envelope.
+ */
+ public function envelope(): Envelope
+ {
+ $from = new Address(config('mail.from.address'), config('mail.from.name'));
+
+ return new Envelope(
+ from: $from,
+ subject: trans('mail.Expiring_Licenses_Report'),
+ );
+ }
+
+ /**
+ * Get the message content definition.
+ */
+ public function content(): Content
+ {
+ return new Content(
+ markdown: 'notifications.markdown.report-expiring-licenses',
+ with: [
+ 'licenses' => $this->licenses,
+ 'threshold' => $this->threshold,
+ ]
+ );
+ }
+
+ /**
+ * Get the attachments for the message.
+ *
+ * @return array<int, \Illuminate\Mail\Mailables\Attachment>
+ */
+ public function attachments(): array
+ {
+ return [];
+ }
+}