diff --git a/app/Email/BaseEmailer.php b/app/Email/BaseEmailer.php index 0f0e315..326b40d 100644 --- a/app/Email/BaseEmailer.php +++ b/app/Email/BaseEmailer.php @@ -3,6 +3,7 @@ namespace App\Email; use App\Exceptions\AppCommonException; +use App\Exceptions\TempFileNotExistsException; use App\Models\Email; use App\Models\EmailAttachment; use App\Models\User; @@ -82,7 +83,17 @@ abstract class BaseEmailer extends Mailable if ($this->__attachments !== null) { $count = $this->__attachments->count(); foreach ($this->__attachments as $attachment) { + + + $filepath = $attachment->filepath; + + + if (!file_exists($filepath)) { + $e = new TempFileNotExistsException(); + throw $e->setFilepath($filepath); + } + $as = $attachment->send_filename; $mime = $attachment->mime; $this->attach($filepath, [ diff --git a/app/Exceptions/TempFileNotExistsException.php b/app/Exceptions/TempFileNotExistsException.php new file mode 100644 index 0000000..d02f389 --- /dev/null +++ b/app/Exceptions/TempFileNotExistsException.php @@ -0,0 +1,21 @@ +filepath = $filepath; + return $this; + } + + public function getFilepath(): string + { + return $this->filepath; + } +} diff --git a/app/Jobs/Email/SimpleEmail.php b/app/Jobs/Email/SimpleEmail.php index 580a36f..13be367 100644 --- a/app/Jobs/Email/SimpleEmail.php +++ b/app/Jobs/Email/SimpleEmail.php @@ -4,8 +4,10 @@ namespace App\Jobs\Email; use App\Codes\QueueName; use App\Email\Sender; +use App\Exceptions\TempFileNotExistsException; use App\Jobs\BaseJob; use App\Models\Email; +use Illuminate\Support\Facades\Log; class SimpleEmail extends BaseJob { @@ -29,6 +31,11 @@ class SimpleEmail extends BaseJob */ public function handle() { - Sender::send($this->emailId); + try { + Sender::send($this->emailId); + } catch (TempFileNotExistsException $e) { + // 一時ファイルが存在しないため、処理終了 + Log::warning(sprintf("ファイル存在しないため、メール送信処理スキップ :%s", $e->getFilepath())); + } } }