mirror of
https://github.com/flarum/core.git
synced 2025-08-02 22:47:33 +02:00
Send Test Mail Feature (#2023)
- Add UI, backend for sending test emails - Change mail settings endpoint to /api/mail/settings
This commit is contained in:
committed by
GitHub
parent
63242edeb3
commit
d1750fecc0
53
src/Api/Controller/SendTestMailController.php
Normal file
53
src/Api/Controller/SendTestMailController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Illuminate\Mail\Message;
|
||||
use Laminas\Diactoros\Response\EmptyResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class SendTestMailController implements RequestHandlerInterface
|
||||
{
|
||||
use AssertPermissionTrait;
|
||||
|
||||
protected $container;
|
||||
|
||||
protected $mailer;
|
||||
|
||||
protected $translator;
|
||||
|
||||
public function __construct(Container $container, Mailer $mailer, TranslatorInterface $translator)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->mailer = $mailer;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$actor = $request->getAttribute('actor');
|
||||
$this->assertAdmin($actor);
|
||||
|
||||
$body = $this->translator->trans('core.email.send_test.body', ['{username}' => $actor->username]);
|
||||
|
||||
$this->mailer->raw($body, function (Message $message) use ($actor) {
|
||||
$message->to($actor->email);
|
||||
$message->subject($this->translator->trans('core.email.send_test.subject'));
|
||||
});
|
||||
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
@@ -309,8 +309,15 @@ return function (RouteCollection $map, RouteHandlerFactory $route) {
|
||||
|
||||
// List available mail drivers, available fields and validation status
|
||||
$map->get(
|
||||
'/mail-settings',
|
||||
'/mail/settings',
|
||||
'mailSettings.index',
|
||||
$route->toController(Controller\ShowMailSettingsController::class)
|
||||
);
|
||||
|
||||
// Send test mail post
|
||||
$map->post(
|
||||
'/mail/test',
|
||||
'mailTest',
|
||||
$route->toController(Controller\SendTestMailController::class)
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user