1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Console/Commands/SendTestEmails.php

76 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2020-09-07 12:18:56 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-07 12:18:56 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-09-07 12:18:56 +02:00
*/
namespace App\Console\Commands;
2023-10-26 04:57:44 +02:00
use App\Jobs\Mail\NinjaMailerObject;
2023-10-25 03:04:36 +02:00
use App\Mail\TestMailServer;
2023-10-26 04:57:44 +02:00
use App\Models\User;
2023-10-25 03:04:36 +02:00
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class SendTestEmails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:send-test-emails';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends Test Emails to check templates';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2020-02-15 12:49:31 +01:00
2023-10-25 03:04:36 +02:00
$to_user = User::first();
2021-06-08 12:39:07 +02:00
2024-01-14 05:05:00 +01:00
$nmo = new NinjaMailerObject();
2023-10-25 03:04:36 +02:00
$nmo->mailable = new TestMailServer('Email Server Works!', config('mail.from.address'));
$nmo->company = $to_user->account->companies()->first();
$nmo->settings = $to_user->account->companies()->first()->settings;
$nmo->to_user = $to_user;
2021-06-08 12:39:07 +02:00
2023-10-25 03:04:36 +02:00
try {
2021-06-08 12:39:07 +02:00
2023-10-25 03:04:36 +02:00
Mail::raw("Test Message", function ($message) {
$message->to(config('mail.from.address'))
->from(config('mail.from.address'), config('mail.from.name'))
->subject('Test Email');
});
2021-06-08 12:39:07 +02:00
2023-10-25 03:04:36 +02:00
} catch(\Exception $e) {
$this->info("Error sending email: " . $e->getMessage());
}
}
}