diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 692fe67c34b7..ecaf942e9e37 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -176,25 +176,17 @@ 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')) + if(stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) { $message = "Either Attachment too large, or recipient has been suppressed."; $this->fail(); + $this->logMailError($e->getMessage(), $this->company->clients()->first()); $this->cleanUpMailers(); return; - // $response = $e->getResponse(); - // $message_body = json_decode($response->getBody()->getContents()); - - // if($message_body && property_exists($message_body, 'Message')){ - // $message = $message_body->Message; - // } - - /*Do not retry if this is a postmark specific issue such as invalid recipient. */ - } //only report once, not on all tries diff --git a/app/Mail/Engine/BaseEmailEngine.php b/app/Mail/Engine/BaseEmailEngine.php index 77c8c6b93631..ebb90796fbc1 100644 --- a/app/Mail/Engine/BaseEmailEngine.php +++ b/app/Mail/Engine/BaseEmailEngine.php @@ -27,6 +27,8 @@ class BaseEmailEngine implements EngineInterface public $attachments = []; + public $attachment_links = []; + public $link; public $text; @@ -37,6 +39,8 @@ class BaseEmailEngine implements EngineInterface public $text_footer; + public int $max_attachment_size = 3000000; + public function setFooter($footer) { $this->footer = $footer; @@ -95,6 +99,14 @@ class BaseEmailEngine implements EngineInterface return $this; } + public function setAttachmentLinks($links) + { + $this->attachment_links = array_merge($this->getAttachmentLinks(), $links); + + return $this; + } + + public function setViewLink($link) { $this->link = $link; @@ -131,6 +143,11 @@ class BaseEmailEngine implements EngineInterface return $this->attachments; } + public function getAttachmentLinks() + { + return $this->attachment_links; + } + public function getFooter() { return $this->footer; diff --git a/app/Mail/Engine/CreditEmailEngine.php b/app/Mail/Engine/CreditEmailEngine.php index 25ac405d38ea..19989905bb18 100644 --- a/app/Mail/Engine/CreditEmailEngine.php +++ b/app/Mail/Engine/CreditEmailEngine.php @@ -18,6 +18,7 @@ use App\Utils\Ninja; use App\Utils\Number; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Lang; +use Illuminate\Support\Facades\URL; class CreditEmailEngine extends BaseEmailEngine { @@ -136,11 +137,19 @@ class CreditEmailEngine extends BaseEmailEngine // Storage::url foreach ($this->credit->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); } foreach ($this->credit->company->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); } } diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index 24b71c8ef579..7f3a0bf417d9 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -23,6 +23,7 @@ use App\Utils\Number; use App\Utils\Traits\MakesHash; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Lang; +use Illuminate\Support\Facades\URL; class InvoiceEmailEngine extends BaseEmailEngine { @@ -136,13 +137,22 @@ class InvoiceEmailEngine extends BaseEmailEngine //attach third party documents if ($this->client->getSetting('document_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { + // Storage::url foreach ($this->invoice->documents as $document) { - $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); } foreach ($this->invoice->company->documents as $document) { - $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); } $line_items = $this->invoice->line_items; @@ -160,7 +170,12 @@ class InvoiceEmailEngine extends BaseEmailEngine ->cursor() ->each(function ($expense) { foreach ($expense->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + } }); } @@ -176,7 +191,12 @@ class InvoiceEmailEngine extends BaseEmailEngine ->cursor() ->each(function ($task) { foreach ($task->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + } }); } diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 5ed690ab8371..6a76d5209efe 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -19,6 +19,7 @@ use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\MakesDates; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\URL; class PaymentEmailEngine extends BaseEmailEngine { @@ -100,7 +101,11 @@ class PaymentEmailEngine extends BaseEmailEngine if ($this->client->getSetting('document_email_attachment') !== false) { foreach ($invoice->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); } } diff --git a/app/Mail/Engine/PurchaseOrderEmailEngine.php b/app/Mail/Engine/PurchaseOrderEmailEngine.php index bc2b65179c71..4f4722381e02 100644 --- a/app/Mail/Engine/PurchaseOrderEmailEngine.php +++ b/app/Mail/Engine/PurchaseOrderEmailEngine.php @@ -27,6 +27,7 @@ use App\Utils\Traits\MakesHash; use App\Utils\VendorHtmlEngine; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Lang; +use Illuminate\Support\Facades\URL; class PurchaseOrderEmailEngine extends BaseEmailEngine { @@ -126,11 +127,6 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine ->setTextBody($text_body); if ($this->vendor->getSetting('pdf_email_attachment') !== false && $this->purchase_order->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { - // if (Ninja::isHosted()) { - // $this->setAttachments([$this->purchase_order->pdf_file_path($this->invitation, 'url', true)]); - // } else { - // $this->setAttachments([$this->purchase_order->pdf_file_path($this->invitation)]); - // } $pdf = (new CreatePurchaseOrderPdf($this->invitation))->rawPdf(); @@ -143,13 +139,19 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine // Storage::url foreach ($this->purchase_order->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]); - // $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]); } foreach ($this->purchase_order->company->documents as $document) { - $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]); - // $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]); } } diff --git a/app/Mail/Engine/QuoteEmailEngine.php b/app/Mail/Engine/QuoteEmailEngine.php index bf38f35b6fc3..03a3be65f988 100644 --- a/app/Mail/Engine/QuoteEmailEngine.php +++ b/app/Mail/Engine/QuoteEmailEngine.php @@ -18,6 +18,7 @@ use App\Utils\Ninja; use App\Utils\Number; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Lang; +use Illuminate\Support\Facades\URL; class QuoteEmailEngine extends BaseEmailEngine { @@ -128,11 +129,19 @@ class QuoteEmailEngine extends BaseEmailEngine // Storage::url foreach ($this->quote->documents as $document) { - $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); } foreach ($this->quote->company->documents as $document) { - $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); + + if($document->size > $this->max_attachment_size) + $this->setAttachmentLinks([" $document->hash]) ."'>". $document->name .""]); + else + $this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]); } } diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 831f2cc0108b..b690a6903345 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -116,6 +116,7 @@ class TemplateEmail extends Mailable 'company' => $company, 'whitelabel' => $this->client->user->account->isPaid() ? true : false, 'logo' => $this->company->present()->logo($settings), + 'links' => $this->build_email->getAttachmentLinks(), ]); foreach ($this->build_email->getAttachments() as $file) { diff --git a/app/Mail/VendorTemplateEmail.php b/app/Mail/VendorTemplateEmail.php index 6e8fb8e1ed8f..1e29bc3b51f1 100644 --- a/app/Mail/VendorTemplateEmail.php +++ b/app/Mail/VendorTemplateEmail.php @@ -109,6 +109,7 @@ class VendorTemplateEmail extends Mailable 'company' => $this->company, 'whitelabel' => $this->vendor->user->account->isPaid() ? true : false, 'logo' => $this->company->present()->logo($settings), + 'links' => $this->build_email->getAttachmentLinks(), ]); diff --git a/resources/views/email/template/client.blade.php b/resources/views/email/template/client.blade.php index 2e3a20080956..e15e5d87e5c8 100644 --- a/resources/views/email/template/client.blade.php +++ b/resources/views/email/template/client.blade.php @@ -24,7 +24,7 @@ supported-color-schemes: light dark; } @if(isset($settings) && $settings->email_style === 'dark') - body { + body { background-color: #1a1a1a !important; color: #ffffff !important; } @@ -109,6 +109,21 @@ z-index:200 !important; position: relative; } + + .doc_links { + + padding-bottom: 10px; + display: inline-block; + + } + + a { + + text-decoration: none; + color: inherit !important; + + } +