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

Fixes for EmailEntity

This commit is contained in:
David Bomba 2021-02-16 23:56:12 +11:00
parent 6e4979f2a1
commit a056f95e13
5 changed files with 63 additions and 28 deletions

View File

@ -43,13 +43,13 @@ class GmailTransport extends Transport
{
/*We should nest the token in the message and then discard it as needed*/
$token = $message->get('GmailToken');
$token = $message->getHeaders()->get('GmailToken');
nlog("gmail transporter token = {$token}");
$message->remove('GmailToken');
$message->getHeaders()->remove('GmailToken');
nlog("inside gmail sender with token {$this->token}");
nlog("inside gmail sender with token {$token}");
$this->beforeSendPerformed($message);

View File

@ -16,6 +16,8 @@ use App\Events\Invoice\InvoiceWasEmailed;
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
use App\Jobs\Mail\BaseMailerJob;
use App\Jobs\Mail\EntityFailedSendMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\TemplateEmail;
use App\Models\Activity;
@ -106,18 +108,29 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
/* Set the correct mail driver */
$this->setMailDriver();
try {
Mail::to($this->invitation->contact->email, $this->invitation->contact->present()->name())
->send(
new TemplateEmail(
$this->email_entity_builder,
$this->invitation->contact
)
);
} catch (\Exception $e) {
$this->entityEmailFailed($e->getMessage());
$this->logMailError($e->getMessage(), $this->entity->client);
}
$nmo = new NinjaMailerObject;
$nmo->mailable = new TemplateEmail($this->email_entity_builder,$this->invitation->contact);
$nmo->company = $this->company;
$nmo->settings = $this->settings;
$nmo->to_user = $this->invitation->contact;
$nmo->entity_string = $this->entity_string;
$nmo->invitation = $this->invitation;
$nmo->reminder_template = $this->reminder_template;
NinjaMailerJob::dispatch($nmo);
// try {
// Mail::to($this->invitation->contact->email, $this->invitation->contact->present()->name())
// ->send(
// new TemplateEmail(
// $this->email_entity_builder,
// $this->invitation->contact
// )
// );
// } catch (\Exception $e) {
// $this->entityEmailFailed($e->getMessage());
// $this->logMailError($e->getMessage(), $this->entity->client);
// }
/* Mark entity sent */
$this->entity->service()->markSent()->save();
@ -136,7 +149,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
}
}
/* Switch statement to handling failure notifications */
/* Switch statement to handle failure notifications */
private function entityEmailFailed($message)
{
switch ($this->entity_string) {

View File

@ -12,10 +12,12 @@
namespace App\Jobs\Mail;
use App\DataMapper\Analytics\EmailFailure;
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Util\SystemLogger;
use App\Libraries\Google\Google;
use App\Libraries\MultiDB;
use App\Mail\TemplateEmail;
use App\Models\ClientContact;
use App\Models\SystemLog;
use App\Models\User;
@ -60,9 +62,10 @@ class NinjaMailerJob implements ShouldQueue
if ($this->nmo->company->is_disabled)
return true;
/*Set the correct database*/
MultiDB::setDb($this->nmo->company->db);
//if we need to set an email driver do it now
/* Set the email driver */
$this->setMailDriver();
//send email
@ -71,11 +74,28 @@ class NinjaMailerJob implements ShouldQueue
Mail::to($this->nmo->to_user->email)
->send($this->nmo->mailable);
} catch (\Exception $e) {
//$this->failed($e);
nlog("error failed with {$e->getMessage()}");
if ($this->nmo->to_user instanceof ClientContact) {
if ($this->nmo->to_user instanceof ClientContact)
$this->logMailError($e->getMessage(), $this->nmo->to_user->client);
}
if($this->nmo->entity_string)
$this->entityEmailFailed($e->getMessage());
}
}
/* Switch statement to handle failure notifications */
private function entityEmailFailed($message)
{
switch ($this->nmo->entity_string) {
case 'invoice':
event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars()));
break;
default:
# code...
break;
}
}

View File

@ -29,4 +29,10 @@ class NinjaMailerObject
public $transport; //not yet used
/* Variable for cascading notifications */
public $entity_string = FALSE;
public $invitation = FALSE;
public $template = FALSE;
}

View File

@ -20,7 +20,6 @@ use Illuminate\Queue\SerializesModels;
class TemplateEmail extends Mailable
{
//use Queueable, SerializesModels;
private $build_email;
@ -37,12 +36,6 @@ class TemplateEmail extends Mailable
$this->client = $contact->client;
}
/**
* Build the message.
*
* @return $this
* @throws \Laracasts\Presenter\Exceptions\PresenterException
*/
public function build()
{
$template_name = 'email.template.'.$this->build_email->getTemplate();
@ -79,7 +72,10 @@ class TemplateEmail extends Mailable
'settings' => $settings,
'company' => $company,
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
]);
])
->withSwiftMessage(function ($message) use($company){
$message->getHeaders()->addTextHeader('Tag', $company->company_key);
});;
//conditionally attach files
if ($settings->pdf_email_attachment !== false && ! empty($this->build_email->getAttachments())) {