Mail listeners to harvest message ids

This commit is contained in:
David Bomba 2021-02-22 11:18:52 +11:00
parent e8d40d2fde
commit c72fcfed64
9 changed files with 84 additions and 7 deletions

View File

@ -23,8 +23,8 @@ class ConnectedAccountController extends BaseController
parent::__construct(); parent::__construct();
} }
/** /**
* Refreshes the data feed with the current Company User. * Connect an OAuth account to a regular email/password combination account
* *
* @param Request $request * @param Request $request
* @return User Refresh Feed. * @return User Refresh Feed.

View File

@ -105,7 +105,7 @@ class EmailEntity implements ShouldQueue
MultiDB::setDB($this->company->db); MultiDB::setDB($this->company->db);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new TemplateEmail($this->email_entity_builder,$this->invitation->contact); $nmo->mailable = new TemplateEmail($this->email_entity_builder,$this->invitation->contact, $this->invitation);
$nmo->company = $this->company; $nmo->company = $this->company;
$nmo->settings = $this->settings; $nmo->settings = $this->settings;
$nmo->to_user = $this->invitation->contact; $nmo->to_user = $this->invitation->contact;

View File

@ -0,0 +1,47 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Mail;
use App\Libraries\MultiDB;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;
use Illuminate\Mail\Events\MessageSent;
class MailSentListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle(MessageSent $event)
{
//MultiDB::setDb($event->company->db);
//$postmark_id = $message->getHeaders()->get('x-pm-message-id')->getValue();
if(property_exists($event->message, 'invitation')){
nlog($event->message->invitation);
}
}
}

View File

@ -31,6 +31,8 @@ class BaseEmailEngine implements EngineInterface
public $text; public $text;
public $invitation;
public function setFooter($footer) public function setFooter($footer)
{ {
$this->footer = $footer; $this->footer = $footer;
@ -141,4 +143,15 @@ class BaseEmailEngine implements EngineInterface
public function build() public function build()
{ {
} }
public function setInvitation($invitation)
{
$this->invitation = $invitation;
}
public function getInvitation()
{
return $this->invitation;
}
} }

View File

@ -85,7 +85,8 @@ class CreditEmailEngine extends BaseEmailEngine
->setBody($body_template) ->setBody($body_template)
->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_credit').'</a>') ->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_credit').'</a>')
->setViewLink($this->invitation->getLink()) ->setViewLink($this->invitation->getLink())
->setViewText(ctrans('texts.view_credit')); ->setViewText(ctrans('texts.view_credit'))
->setInvitation($this->invitation);
if ($this->client->getSetting('pdf_email_attachment') !== false) { if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]); $this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);

View File

@ -94,7 +94,8 @@ class InvoiceEmailEngine extends BaseEmailEngine
->setBody($body_template) ->setBody($body_template)
->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_invoice').'</a>') ->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_invoice').'</a>')
->setViewLink($this->invitation->getLink()) ->setViewLink($this->invitation->getLink())
->setViewText(ctrans('texts.view_invoice')); ->setViewText(ctrans('texts.view_invoice'))
->setInvitation($this->invitation);
if ($this->client->getSetting('pdf_email_attachment') !== false) { if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments([$this->invoice->pdf_file_path()]); $this->setAttachments([$this->invoice->pdf_file_path()]);

View File

@ -85,7 +85,9 @@ class QuoteEmailEngine extends BaseEmailEngine
->setBody($body_template) ->setBody($body_template)
->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_quote').'</a>') ->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_quote').'</a>')
->setViewLink($this->invitation->getLink()) ->setViewLink($this->invitation->getLink())
->setViewText(ctrans('texts.view_quote')); ->setViewText(ctrans('texts.view_quote'))
->setInvitation($this->invitation);
if ($this->client->getSetting('pdf_email_attachment') !== false) { if ($this->client->getSetting('pdf_email_attachment') !== false) {
// $this->setAttachments([$this->quote->pdf_file_path()]); // $this->setAttachments([$this->quote->pdf_file_path()]);

View File

@ -29,7 +29,9 @@ class TemplateEmail extends Mailable
private $company; private $company;
public function __construct($build_email, ClientContact $contact) private $invitation;
public function __construct($build_email, ClientContact $contact, $invitation = null)
{ {
$this->build_email = $build_email; $this->build_email = $build_email;
@ -38,6 +40,8 @@ class TemplateEmail extends Mailable
$this->client = $contact->client; $this->client = $contact->client;
$this->company = $contact->company; $this->company = $contact->company;
$this->invitation = $invitation;
} }
public function build() public function build()
@ -77,6 +81,7 @@ class TemplateEmail extends Mailable
]) ])
->withSwiftMessage(function ($message) use($company){ ->withSwiftMessage(function ($message) use($company){
$message->getHeaders()->addTextHeader('Tag', $company->company_key); $message->getHeaders()->addTextHeader('Tag', $company->company_key);
$message->invitation = $this->invitation;
}); });
//conditionally attach files //conditionally attach files

View File

@ -136,6 +136,7 @@ use App\Listeners\Invoice\InvoiceRestoredActivity;
use App\Listeners\Invoice\InvoiceReversedActivity; use App\Listeners\Invoice\InvoiceReversedActivity;
use App\Listeners\Invoice\InvoiceViewedActivity; use App\Listeners\Invoice\InvoiceViewedActivity;
use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceActivity;
use App\Listeners\Mail\MailSentListener;
use App\Listeners\Misc\InvitationViewedListener; use App\Listeners\Misc\InvitationViewedListener;
use App\Listeners\Payment\PaymentEmailFailureActivity; use App\Listeners\Payment\PaymentEmailFailureActivity;
use App\Listeners\Payment\PaymentEmailedActivity; use App\Listeners\Payment\PaymentEmailedActivity;
@ -157,6 +158,8 @@ use App\Listeners\User\RestoredUserActivity;
use App\Listeners\User\UpdateUserLastLogin; use App\Listeners\User\UpdateUserLastLogin;
use App\Listeners\User\UpdatedUserActivity; use App\Listeners\User\UpdatedUserActivity;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Mail\Events\MessageSent;
class EventServiceProvider extends ServiceProvider class EventServiceProvider extends ServiceProvider
{ {
@ -166,6 +169,11 @@ class EventServiceProvider extends ServiceProvider
* @var array * @var array
*/ */
protected $listen = [ protected $listen = [
MessageSending::class =>[
],
MessageSent::class => [
MailSentListener::class,
],
UserWasCreated::class => [ UserWasCreated::class => [
CreatedUserActivity::class, CreatedUserActivity::class,
SendVerificationNotification::class, SendVerificationNotification::class,