-
If I want to test the mail connection without sending mail how to do it? |
Beta Was this translation helpful? Give feedback.
Answered by
vlados
Jan 28, 2023
Replies: 2 comments 1 reply
-
This is my solution: <?php
namespace App\Checks;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
class MailCheck extends Check
{
public function run(): Result
{
$this->label = 'Mail ('.config('mail.default').')';
switch (config('mail.default')) {
case 'smtp':
return $this->checkSmtp();
default:
$result = Result::make();
return $result->failed('Mailer '.config('mail.default').' is not supported');
}
}
private function checkSmtp(): Result
{
$result = Result::make();
try {
$transport = new EsmtpTransport(config('mail.mailers.smtp.host'), config('mail.mailers.smtp.port'), config('mail.mailers.smtp.encryption'));
$transport->setUsername(config('mail.mailers.smtp.username'));
$transport->setPassword(config('mail.mailers.smtp.password'));
$transport->start();
return $result->ok();
} catch (\Exception $e) {
return $result->failed($e->getMessage());
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vlados
-
As soon as the package is created, any help is welcome https://github.com/laraxot/smtp-health-check |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my solution: