update: add test send mail

This commit is contained in:
tokumeikoi 2021-11-30 16:23:46 +08:00
parent 05769ea591
commit 30aec3d8e9
4 changed files with 22 additions and 18 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\ConfigSave; use App\Http\Requests\Admin\ConfigSave;
use App\Jobs\SendEmailJob;
use App\Services\TelegramService; use App\Services\TelegramService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Utils\Dict; use App\Utils\Dict;
@ -35,20 +36,19 @@ class ConfigController extends Controller
public function testSendMail(Request $request) public function testSendMail(Request $request)
{ {
$email = $request->session()->get('email'); $obj = new SendEmailJob([
$subject = 'This is v2board test email'; 'email' => $request->session()->get('email'),
try { 'subject' => 'This is v2board test email',
Mail::raw( 'template_name' => 'notify',
'This is v2board test email', 'template_value' => [
function ($message) use ($email, $subject) { 'name' => config('v2board.app_name', 'V2Board'),
$message->to($email)->subject($subject); 'content' => 'This is v2board test email',
} 'url' => config('v2board.app_url')
); ]
} catch (\Exception $e) { ]);
abort(500, $e->getMessage());
}
return response([ return response([
'data' => true 'data' => true,
'log' => $obj->handle()
]); ]);
} }

View File

@ -60,11 +60,15 @@ class SendEmailJob implements ShouldQueue
$error = $e->getMessage(); $error = $e->getMessage();
} }
MailLog::create([ $log = [
'email' => $params['email'], 'email' => $params['email'],
'subject' => $params['subject'], 'subject' => $params['subject'],
'template_name' => $params['template_name'], 'template_name' => $params['template_name'],
'error' => isset($error) ? $error : NULL 'error' => isset($error) ? $error : NULL
]); ];
MailLog::create($log);
$log['config'] = config('mail');
return $log;
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long