1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Better logging for bounced emails

This commit is contained in:
David Bomba 2023-11-18 16:45:00 +11:00
parent 964294185e
commit 913edb706a
2 changed files with 35 additions and 4 deletions

View File

@ -24,6 +24,7 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\SystemLog;
use App\Models\User;
use App\Repositories\ActivityRepository;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use GuzzleHttp\Exception\ClientException;
@ -164,7 +165,7 @@ class NinjaMailerJob implements ShouldQueue
* this merges a text string with a json object
* need to harvest the ->Message property using the following
*/
if (stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) {
if (stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) {
$message = "Either Attachment too large, or recipient has been suppressed.";
$this->fail();
@ -174,6 +175,20 @@ class NinjaMailerJob implements ShouldQueue
return;
}
if (stripos($e->getMessage(), 'code 406')) {
$email = $this->nmo->to_user->email ?? '';
$message = "Recipient {$email} has been suppressed and cannot receive emails from you.";
$this->fail();
$this->logMailError($message, $this->company->clients()->first());
$this->cleanUpMailers();
return;
}
//only report once, not on all tries
if ($this->attempts() == $this->tries) {
/* If the is an entity attached to the message send a failure mailer */

View File

@ -272,7 +272,8 @@ class Email implements ShouldQueue
nlog("Mailer failed with {$e->getMessage()}");
$message = $e->getMessage();
if (stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) {
if (stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) {
$message = "Either Attachment too large, or recipient has been suppressed.";
$this->fail();
@ -282,6 +283,21 @@ class Email implements ShouldQueue
return;
}
if (stripos($e->getMessage(), 'code 406')) {
$address_object = reset($this->email_object->to);
$email = $address_object->address ?? '';
$message = "Recipient {$email} has been suppressed and cannot receive emails from you.";
$this->fail();
$this->logMailError($message, $this->company->clients()->first());
$this->cleanUpMailers();
return;
}
/**
* Post mark buries the proper message in a a guzzle response
* this merges a text string with a json object