mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-08 05:54:47 +00:00
Upgrade mail configuration (#455)
* Upgrade the mail configuration * Update mail configuration to match Laravel 12 * Update mail configuration to properly set none or null * Pint code * Upgrade Symfony Mailers
This commit is contained in:
committed by
GitHub
parent
d1bca362de
commit
bae8dbe083
@@ -7,6 +7,7 @@ use App\Http\Requests\MailEnvironmentRequest;
|
||||
use App\Mail\TestMail;
|
||||
use App\Models\Setting;
|
||||
use App\Space\EnvironmentManager;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Mail;
|
||||
@@ -14,17 +15,26 @@ use Mail;
|
||||
class MailConfigurationController extends Controller
|
||||
{
|
||||
/**
|
||||
* The environment manager
|
||||
*
|
||||
* @var EnvironmentManager
|
||||
*/
|
||||
protected $environmentManager;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public function __construct(EnvironmentManager $environmentManager)
|
||||
{
|
||||
$this->environmentManager = $environmentManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the mail environment variables
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function saveMailEnvironment(MailEnvironmentRequest $request)
|
||||
{
|
||||
@@ -40,32 +50,79 @@ class MailConfigurationController extends Controller
|
||||
return response()->json($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mail environment variables
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function getMailEnvironment()
|
||||
{
|
||||
$this->authorize('manage email config');
|
||||
|
||||
$driver = config('mail.default');
|
||||
|
||||
// Base data that's always available
|
||||
$MailData = [
|
||||
'mail_driver' => config('mail.driver'),
|
||||
'mail_host' => config('mail.host'),
|
||||
'mail_port' => config('mail.port'),
|
||||
'mail_username' => config('mail.username'),
|
||||
'mail_password' => config('mail.password'),
|
||||
'mail_encryption' => is_null(config('mail.encryption')) ? 'none' : config('mail.encryption'),
|
||||
'mail_driver' => $driver,
|
||||
'from_name' => config('mail.from.name'),
|
||||
'from_mail' => config('mail.from.address'),
|
||||
'mail_mailgun_endpoint' => config('services.mailgun.endpoint'),
|
||||
'mail_mailgun_domain' => config('services.mailgun.domain'),
|
||||
'mail_mailgun_secret' => config('services.mailgun.secret'),
|
||||
'mail_ses_key' => config('services.ses.key'),
|
||||
'mail_ses_secret' => config('services.ses.secret'),
|
||||
'mail_ses_region' => config('services.ses.region'),
|
||||
];
|
||||
|
||||
// Driver-specific configuration
|
||||
switch ($driver) {
|
||||
case 'smtp':
|
||||
$MailData = array_merge($MailData, [
|
||||
'mail_host' => config('mail.mailers.smtp.host'),
|
||||
'mail_port' => config('mail.mailers.smtp.port'),
|
||||
'mail_username' => config('mail.mailers.smtp.username'),
|
||||
'mail_password' => config('mail.mailers.smtp.password'),
|
||||
'mail_encryption' => config('mail.mailers.smtp.scheme') ?? 'none',
|
||||
'mail_scheme' => config('mail.mailers.smtp.scheme'),
|
||||
'mail_url' => config('mail.mailers.smtp.url'),
|
||||
'mail_timeout' => config('mail.mailers.smtp.timeout'),
|
||||
'mail_local_domain' => config('mail.mailers.smtp.local_domain'),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'mailgun':
|
||||
$MailData = array_merge($MailData, [
|
||||
'mail_mailgun_domain' => config('mail.mailers.mailgun.domain'),
|
||||
'mail_mailgun_secret' => config('mail.mailers.mailgun.secret'),
|
||||
'mail_mailgun_endpoint' => config('mail.mailers.mailgun.endpoint'),
|
||||
'mail_mailgun_scheme' => config('mail.mailers.mailgun.scheme'),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'ses':
|
||||
$MailData = array_merge($MailData, [
|
||||
'mail_ses_key' => config('services.ses.key'),
|
||||
'mail_ses_secret' => config('services.ses.secret'),
|
||||
'mail_ses_region' => config('services.ses.region'),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'sendmail':
|
||||
$MailData = array_merge($MailData, [
|
||||
'mail_sendmail_path' => config('mail.mailers.sendmail.path'),
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
// For unknown drivers, return minimal configuration
|
||||
break;
|
||||
}
|
||||
|
||||
return response()->json($MailData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available mail drivers
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function getMailDrivers()
|
||||
{
|
||||
@@ -82,6 +139,14 @@ class MailConfigurationController extends Controller
|
||||
return response()->json($drivers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the email configuration
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testEmailConfig(Request $request)
|
||||
{
|
||||
$this->authorize('manage email config');
|
||||
|
||||
Reference in New Issue
Block a user