mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Test postmark connection before storing credentials into the app
This commit is contained in:
@@ -19,7 +19,9 @@ class TestMailgunConnectionAction
|
||||
// Set temporary mail connection
|
||||
config([
|
||||
'mail' => [
|
||||
'driver' => 'mailgun',
|
||||
'driver' => 'mailgun',
|
||||
'from.address' => $credentials['sender'],
|
||||
'from.name' => $credentials['sender'],
|
||||
],
|
||||
'services' => [
|
||||
'mailgun' => [
|
||||
@@ -31,7 +33,7 @@ class TestMailgunConnectionAction
|
||||
]);
|
||||
|
||||
// Send test email
|
||||
Mail::to('test@hi5ve.digital')->send(new TestMail('example@domain.com'));
|
||||
Mail::to($credentials['sender'])->send(new TestMail($credentials['sender']));
|
||||
} catch (TransportException | LogicException $error) {
|
||||
abort(
|
||||
response()->json([
|
||||
|
||||
34
src/Domain/Settings/Actions/TestPostmarkConnectionAction.php
Normal file
34
src/Domain/Settings/Actions/TestPostmarkConnectionAction.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Domain\Settings\Actions;
|
||||
|
||||
use Mail;
|
||||
use Domain\Settings\Mail\TestMail;
|
||||
use Symfony\Component\Mailer\Exception\LogicException;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
|
||||
class TestPostmarkConnectionAction
|
||||
{
|
||||
public function __invoke(array $credentials)
|
||||
{
|
||||
try {
|
||||
// Set temporary mail connection
|
||||
config([
|
||||
'mail.driver' => 'postmark',
|
||||
'mail.from.address' => $credentials['sender'],
|
||||
'mail.from.name' => $credentials['sender'],
|
||||
'services.postmark.token' => $credentials['token'],
|
||||
]);
|
||||
|
||||
// Send test email
|
||||
Mail::to($credentials['sender'])->send(new TestMail($credentials['sender']));
|
||||
} catch (TransportException | LogicException $error) {
|
||||
abort(
|
||||
response()->json([
|
||||
'type' => 'mailer-connection-error',
|
||||
'title' => 'Mail Connection Error',
|
||||
'message' => $error->getMessage(),
|
||||
], 401)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,11 @@ class TestSMTPConnectionAction
|
||||
],
|
||||
]]);
|
||||
|
||||
// Get sender
|
||||
$sender = $credentials['email'] ?? $credentials['username'];
|
||||
|
||||
// Send test email
|
||||
Mail::to('test@hi5ve.digital')->send(new TestMail($sender));
|
||||
Mail::to($sender)->send(new TestMail($sender));
|
||||
} catch (TransportException | LogicException $error) {
|
||||
abort(
|
||||
response()->json([
|
||||
|
||||
@@ -5,11 +5,13 @@ use Artisan;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Domain\Settings\Actions\TestSMTPConnectionAction;
|
||||
use Domain\Settings\Actions\TestMailgunConnectionAction;
|
||||
use Domain\Settings\Actions\TestPostmarkConnectionAction;
|
||||
use Domain\Settings\Requests\StoreEmailCredentialsRequest;
|
||||
|
||||
class StoreEmailCredentialsController
|
||||
{
|
||||
public function __construct(
|
||||
private TestPostmarkConnectionAction $testPostmarkConnection,
|
||||
private TestMailgunConnectionAction $testMailgunConnection,
|
||||
private TestSMTPConnectionAction $testSMTPConnection,
|
||||
) {
|
||||
@@ -38,16 +40,23 @@ class StoreEmailCredentialsController
|
||||
'domain' => $request->input('mailgun.domain'),
|
||||
'secret' => $request->input('mailgun.secret'),
|
||||
'endpoint' => $request->input('mailgun.endpoint'),
|
||||
'sender' => $request->input('mailgun.sender'),
|
||||
]),
|
||||
'postmark' => ($this->testPostmarkConnection)([
|
||||
'token' => $request->input('postmark.token'),
|
||||
'sender' => $request->input('postmark.sender'),
|
||||
]),
|
||||
};
|
||||
|
||||
$mail = [
|
||||
'log' => [
|
||||
'MAIL_DRIVER' => 'log',
|
||||
'MAIL_DRIVER' => 'log',
|
||||
],
|
||||
'postmark' => [
|
||||
'MAIL_DRIVER' => 'postmark',
|
||||
'POSTMARK_TOKEN' => $request->input('postmark.token'),
|
||||
'MAIL_DRIVER' => 'postmark',
|
||||
'POSTMARK_TOKEN' => $request->input('postmark.token'),
|
||||
'MAIL_FROM_ADDRESS' => $request->input('postmark.sender'),
|
||||
'MAIL_FROM_NAME' => $request->input('postmark.sender'),
|
||||
],
|
||||
'smtp' => [
|
||||
'MAIL_DRIVER' => 'smtp',
|
||||
@@ -56,8 +65,8 @@ class StoreEmailCredentialsController
|
||||
'MAIL_USERNAME' => $request->input('smtp.username'),
|
||||
'MAIL_PASSWORD' => $request->input('smtp.password'),
|
||||
'MAIL_ENCRYPTION' => $request->input('smtp.encryption') ?? '',
|
||||
'MAIL_FROM_ADDRESS' => $request->input('smtp.email') ?? '"${MAIL_USERNAME}"',
|
||||
'MAIL_FROM_NAME' => $request->input('smtp.email') ?? '"${MAIL_USERNAME}"',
|
||||
'MAIL_FROM_ADDRESS' => $request->input('smtp.email') ?? $request->input('smtp.username'),
|
||||
'MAIL_FROM_NAME' => $request->input('smtp.email') ?? $request->input('smtp.username'),
|
||||
],
|
||||
'ses' => [
|
||||
'MAIL_DRIVER' => 'ses',
|
||||
@@ -67,10 +76,12 @@ class StoreEmailCredentialsController
|
||||
'AWS_SESSION_TOKEN' => $request->input('ses.session_token'),
|
||||
],
|
||||
'mailgun' => [
|
||||
'MAIL_DRIVER' => 'mailgun',
|
||||
'MAILGUN_DOMAIN' => $request->input('mailgun.domain'),
|
||||
'MAILGUN_SECRET' => $request->input('mailgun.secret'),
|
||||
'MAILGUN_ENDPOINT' => $request->input('mailgun.endpoint'),
|
||||
'MAIL_DRIVER' => 'mailgun',
|
||||
'MAILGUN_DOMAIN' => $request->input('mailgun.domain'),
|
||||
'MAILGUN_SECRET' => $request->input('mailgun.secret'),
|
||||
'MAILGUN_ENDPOINT' => $request->input('mailgun.endpoint'),
|
||||
'MAIL_FROM_ADDRESS' => $request->input('mailgun.sender'),
|
||||
'MAIL_FROM_NAME' => $request->input('mailgun.sender'),
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Domain\Settings\DTO\S3CredentialsData;
|
||||
use Domain\Settings\Actions\TestS3ConnectionAction;
|
||||
use Domain\Settings\Actions\TestSMTPConnectionAction;
|
||||
use Domain\Settings\Actions\TestMailgunConnectionAction;
|
||||
use Domain\Settings\Actions\TestPostmarkConnectionAction;
|
||||
use Domain\SetupWizard\Requests\StoreEnvironmentSetupRequest;
|
||||
|
||||
class StoreEnvironmentSettingsController extends Controller
|
||||
@@ -16,6 +17,7 @@ class StoreEnvironmentSettingsController extends Controller
|
||||
private TestS3ConnectionAction $testS3Connection,
|
||||
private TestSMTPConnectionAction $testSMTPConnection,
|
||||
private TestMailgunConnectionAction $testMailgunConnection,
|
||||
private TestPostmarkConnectionAction $testPostmarkConnection,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -45,6 +47,11 @@ class StoreEnvironmentSettingsController extends Controller
|
||||
'domain' => $request->input('mailgun.domain'),
|
||||
'secret' => $request->input('mailgun.secret'),
|
||||
'endpoint' => $request->input('mailgun.endpoint'),
|
||||
'sender' => $request->input('mailgun.sender'),
|
||||
]),
|
||||
'postmark' => ($this->testPostmarkConnection)([
|
||||
'token' => $request->input('postmark.token'),
|
||||
'sender' => $request->input('postmark.sender'),
|
||||
]),
|
||||
};
|
||||
|
||||
@@ -85,11 +92,13 @@ class StoreEnvironmentSettingsController extends Controller
|
||||
],
|
||||
'mail' => [
|
||||
'log' => [
|
||||
'MAIL_DRIVER' => 'log',
|
||||
'MAIL_DRIVER' => 'log',
|
||||
],
|
||||
'postmark' => [
|
||||
'MAIL_DRIVER' => 'postmark',
|
||||
'POSTMARK_TOKEN' => $request->input('postmark.token'),
|
||||
'MAIL_DRIVER' => 'postmark',
|
||||
'POSTMARK_TOKEN' => $request->input('postmark.token'),
|
||||
'MAIL_FROM_ADDRESS' => $request->input('postmark.sender'),
|
||||
'MAIL_FROM_NAME' => $request->input('postmark.sender'),
|
||||
],
|
||||
'smtp' => [
|
||||
'MAIL_DRIVER' => 'smtp',
|
||||
@@ -98,8 +107,8 @@ class StoreEnvironmentSettingsController extends Controller
|
||||
'MAIL_USERNAME' => $request->input('smtp.username'),
|
||||
'MAIL_PASSWORD' => $request->input('smtp.password'),
|
||||
'MAIL_ENCRYPTION' => $request->input('smtp.encryption') ?? '',
|
||||
'MAIL_FROM_ADDRESS' => $request->input('smtp.email') ?? '"${MAIL_USERNAME}"',
|
||||
'MAIL_FROM_NAME' => $request->input('smtp.email') ?? '"${MAIL_USERNAME}"',
|
||||
'MAIL_FROM_ADDRESS' => $request->input('smtp.email') ?? $request->input('smtp.username'),
|
||||
'MAIL_FROM_NAME' => $request->input('smtp.email') ?? $request->input('smtp.username'),
|
||||
],
|
||||
'ses' => [
|
||||
'MAIL_DRIVER' => 'ses',
|
||||
@@ -109,10 +118,12 @@ class StoreEnvironmentSettingsController extends Controller
|
||||
'AWS_SESSION_TOKEN' => $request->input('ses.session_token'),
|
||||
],
|
||||
'mailgun' => [
|
||||
'MAIL_DRIVER' => 'mailgun',
|
||||
'MAILGUN_DOMAIN' => $request->input('mailgun.domain'),
|
||||
'MAILGUN_SECRET' => $request->input('mailgun.secret'),
|
||||
'MAILGUN_ENDPOINT' => $request->input('mailgun.endpoint'),
|
||||
'MAIL_DRIVER' => 'mailgun',
|
||||
'MAILGUN_DOMAIN' => $request->input('mailgun.domain'),
|
||||
'MAILGUN_SECRET' => $request->input('mailgun.secret'),
|
||||
'MAILGUN_ENDPOINT' => $request->input('mailgun.endpoint'),
|
||||
'MAIL_FROM_ADDRESS' => $request->input('mailgun.sender'),
|
||||
'MAIL_FROM_NAME' => $request->input('mailgun.sender'),
|
||||
],
|
||||
],
|
||||
'environment' => [
|
||||
|
||||
Reference in New Issue
Block a user