diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index a80f148ccdfc..c6ab3c30f197 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -116,13 +116,13 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue $this->invitation->contact->client ) ); - } catch (Swift_TransportException $e) { + } catch (\Exception $e) { + $this->failed($e); $this->entityEmailFailed($e->getMessage()); + $this->logMailError($e->getMessage(), $this->entity->client); } - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->entity->client); - } else { + if (count(Mail::failures()) == 0) { $this->entityEmailSucceeded(); } @@ -130,19 +130,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue $this->entity->service()->markSent()->save(); } - public function failed($exception = null) - { - info('the job failed'); - - $job_failure = new EmailInvoiceFailure(); - $job_failure->string_metric5 = $this->entity_string; - $job_failure->string_metric6 = $exception->getMessage(); - - LightLogs::create($job_failure) - ->batch(); - - } - private function resolveEntityString() :string { if($this->invitation instanceof InvoiceInvitation) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 11946f323950..ad3619923105 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -94,9 +94,15 @@ class ZipInvoices extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); - Mail::to($this->email) - ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); + try { + Mail::to($this->email) + ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); + } + catch (\Exception $e) { + $this->failed($e); + } + UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); } } diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index 62e0d462f8b3..2ca18b4a8916 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -90,15 +90,9 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); - } catch (Swift_TransportException $e) { - $this->failed($e->getMessage()); - //$this->entityEmailFailed($e->getMessage()); - } - - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->payment->client); - } else { - // $this->entityEmailSucceeded(); + } catch (\Exception $e) { + $this->failed($e); + $this->logMailError($e->getMessage(), $this->payment->client); } } diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 062c1d857cbc..88b120913ee4 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -88,13 +88,15 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue $mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build(); $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; - //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + try { + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + }catch(\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->entity->client); - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->entity->client); } + } } diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index 4dad5c068e1f..ba01dd8b88f1 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -89,12 +89,15 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + try{ + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->entity->client); - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->invoice->client); } } } diff --git a/app/Jobs/Mail/MailRouter.php b/app/Jobs/Mail/MailRouter.php index db6ebd423a58..e0dcd4b31020 100644 --- a/app/Jobs/Mail/MailRouter.php +++ b/app/Jobs/Mail/MailRouter.php @@ -22,7 +22,6 @@ use App\Models\Company; use App\Models\SystemLog; use App\Models\User; use App\Providers\MailServiceProvider; -use Dacastro4\LaravelGmail\Services\Message\Mail; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -77,12 +76,16 @@ class MailRouter extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); //send email - Mail::to($this->to_user->email) - ->send($this->mailable); - - //catch errors - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->to_user); + try { + Mail::to($this->to_user->email) + ->send($this->mailable); } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->to_user); + + } + } } diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index d06dd7cc994d..1c405d477ce8 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -100,13 +100,17 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue $mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()]; //send email - Mail::to($company_user->user->email) - ->send(new EntityNotificationMailer($mail_obj)); - - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->client); + try { + Mail::to($company_user->user->email) + ->send(new EntityNotificationMailer($mail_obj)); } + catch(\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->client); + + } + } }); } diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 83af0eae8b38..5e751b333f79 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -95,33 +95,15 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue info("mailing failed with message " . $e->getMessage()); event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); + $this->failed($e); return $this->logMailError($e->getMessage(), $this->payment->client); } - // if (count(Mail::failures()) > 0) { - // info("logging mail failures"); - // info(print_r(Mail::failures(),1)); - - - // } - event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); } } - public function failed($exception = null) - { - info('the job failed'); - - $job_failure = new EmailInvoiceFailure(); - $job_failure->string_metric5 = 'payment'; - $job_failure->string_metric6 = $exception->getMessage(); - - LightLogs::create($job_failure) - ->batch(); - - } } diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index 02a788a3f1c0..fb3a963d84a6 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -72,16 +72,21 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue $mail_obj->data = $this->getData(); //Send email via a Mailable class + // + try { Mail::to($this->old_email) ->send(new UserNotificationMailer($mail_obj)); Mail::to($this->new_email) ->send(new UserNotificationMailer($mail_obj)); - - //Catch errors and report. - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->company); } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->company->owner()); + + } + } private function getData()