1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Error handling for emails

This commit is contained in:
David Bomba 2020-08-12 12:16:44 +10:00
parent 941e790a95
commit de24d00315
3 changed files with 24 additions and 14 deletions

View File

@ -725,10 +725,6 @@ class InvoiceController extends BaseController
});
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
}
if (!$bulk) {
return response()->json(['message' => 'email sent'], 200);
}

View File

@ -22,6 +22,7 @@ use App\Models\Company;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\SystemLog;
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -75,18 +76,30 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue
$this->setMailDriver();
Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name())
->send(
new TemplateEmail(
$this->email_builder,
$this->invoice_invitation->contact->user,
$this->invoice_invitation->contact->client
)
);
try {
Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name())
->send(
new TemplateEmail(
$this->email_builder,
$this->invoice_invitation->contact->user,
$this->invoice_invitation->contact->client
)
);
}
catch (\Swift_TransportException $e) {
event(new InvoiceWasEmailedAndFailed($this->invoice_invitation->invoice, $this->company, $e->getMessage(), Ninja::eventVars()));
}
if (count(Mail::failures()) > 0) {
return $this->logMailError(Mail::failures(), $this->invoice->client);
}
else{
event(new InvoiceWasEmailed($this->invoice_invitation, $this->company, Ninja::eventVars()));
}
}

View File

@ -47,10 +47,11 @@ class InvoiceEmailFailedActivity implements ShouldQueue
$fields = new \stdClass;
$fields->invoice_id = $event->invoice->id;
$fields->client_id = $event->invoice->client_id;
$fields->user_id = $event->invoice->user_id;
$fields->client_id = $event->invoice->client_id;
$fields->user_id = $event->invoice->user_id;
$fields->company_id = $event->invoice->company_id;
$fields->activity_type_id = Activity::EMAIL_INVOICE_FAILED;
$fields->notes = $event->errors;
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
}