mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Attachments with GMail transport (#3726)
* Refactor mailers * Fixes for mailer * Fixes for approving a quote * Refactor emailer * Refactor emailer * Attach files with GMail transport * Attach files to GMail transport
This commit is contained in:
parent
d5ae025df0
commit
8ab0238f3f
@ -26,6 +26,7 @@ class CloneQuoteToInvoiceFactory
|
|||||||
unset($quote_array['client']);
|
unset($quote_array['client']);
|
||||||
unset($quote_array['company']);
|
unset($quote_array['company']);
|
||||||
unset($quote_array['hashed_id']);
|
unset($quote_array['hashed_id']);
|
||||||
|
unset($quote_array['invoice_id']);
|
||||||
unset($quote_array['id']);
|
unset($quote_array['id']);
|
||||||
|
|
||||||
foreach($quote_array as $key => $value)
|
foreach($quote_array as $key => $value)
|
||||||
|
@ -62,8 +62,14 @@ class GmailTransport extends Transport
|
|||||||
$this->gmail->cc($message->getCc());
|
$this->gmail->cc($message->getCc());
|
||||||
$this->gmail->bcc($message->getBcc());
|
$this->gmail->bcc($message->getBcc());
|
||||||
|
|
||||||
|
\Log::error(print_r($message->getChildren(),1));
|
||||||
|
|
||||||
|
foreach($message->getChildren() as $child)
|
||||||
|
$this->gmail->attach($child); //todo this should 'just work'
|
||||||
|
|
||||||
$this->gmail->send();
|
$this->gmail->send();
|
||||||
|
|
||||||
|
|
||||||
$this->sendPerformed($message);
|
$this->sendPerformed($message);
|
||||||
|
|
||||||
return $this->numberOfRecipients($message);
|
return $this->numberOfRecipients($message);
|
||||||
|
@ -14,7 +14,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Helpers\Email\InvoiceEmail;
|
use App\Helpers\Email\InvoiceEmail;
|
||||||
use App\Http\Requests\Email\SendEmailRequest;
|
use App\Http\Requests\Email\SendEmailRequest;
|
||||||
use App\Jobs\Invoice\EmailInvoice;
|
use App\Jobs\Invoice\EmailInvoice;
|
||||||
use App\Jobs\Mail\EntityMailer;
|
use App\Jobs\Mail\EntitySentMailer;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
@ -122,7 +122,7 @@ class EmailController extends BaseController
|
|||||||
|
|
||||||
$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
||||||
|
|
||||||
EntityMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
|
EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
class EntityMailer extends BaseMailerJob implements ShouldQueue
|
class EntitySentMailer extends BaseMailerJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ class EntityMailer extends BaseMailerJob implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
info("entity sent mailer");
|
||||||
//Set DB
|
//Set DB
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
@ -63,8 +64,8 @@ class EntityMailer extends BaseMailerJob implements ShouldQueue
|
|||||||
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
|
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
|
||||||
|
|
||||||
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build();
|
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build();
|
||||||
$mail_obj->from = $this->entity->user->present()->name();
|
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
|
||||||
|
|
||||||
//send email
|
//send email
|
||||||
Mail::to($this->user->email)
|
Mail::to($this->user->email)
|
||||||
->send(new EntityNotificationMailer($mail_obj));
|
->send(new EntityNotificationMailer($mail_obj));
|
94
app/Jobs/Mail/EntityViewedMailer.php
Normal file
94
app/Jobs/Mail/EntityViewedMailer.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Mail;
|
||||||
|
|
||||||
|
use App\Jobs\Util\SystemLogger;
|
||||||
|
use App\Libraries\Google\Google;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Mail\Admin\EntityNotificationMailer;
|
||||||
|
use App\Mail\Admin\EntityViewedObject;
|
||||||
|
use App\Models\SystemLog;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Providers\MailServiceProvider;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public $invitation;
|
||||||
|
|
||||||
|
public $entity_type;
|
||||||
|
|
||||||
|
public $entity;
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($invitation, $entity_type, $user, $company)
|
||||||
|
{
|
||||||
|
$this->company = $company;
|
||||||
|
|
||||||
|
$this->user = $user;
|
||||||
|
|
||||||
|
$this->invitation = $invitation;
|
||||||
|
|
||||||
|
$this->entity = $invitation->{$entity_type};
|
||||||
|
|
||||||
|
$this->entity_type = $entity_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
info("entity viewed mailer");
|
||||||
|
|
||||||
|
//Set DB
|
||||||
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
|
//if we need to set an email driver do it now
|
||||||
|
$this->setMailDriver($this->entity->client->getSetting('email_sending_method'));
|
||||||
|
|
||||||
|
$mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build();
|
||||||
|
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
|
||||||
|
|
||||||
|
//send email
|
||||||
|
Mail::to($this->user->email)
|
||||||
|
->send(new EntityNotificationMailer($mail_obj));
|
||||||
|
|
||||||
|
//catch errors
|
||||||
|
if (count(Mail::failures()) > 0) {
|
||||||
|
$this->logMailError(Mail::failures());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logMailError($errors)
|
||||||
|
{
|
||||||
|
SystemLogger::dispatch(
|
||||||
|
$errors,
|
||||||
|
SystemLog::CATEGORY_MAIL,
|
||||||
|
SystemLog::EVENT_MAIL_SEND,
|
||||||
|
SystemLog::TYPE_FAILURE,
|
||||||
|
$this->invoice->client
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Listeners\Invoice;
|
namespace App\Listeners\Invoice;
|
||||||
|
|
||||||
|
use App\Jobs\Mail\EntitySentMailer;
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
@ -57,7 +58,7 @@ class InvoiceEmailedNotification implements ShouldQueue
|
|||||||
//This allows us better control of how we
|
//This allows us better control of how we
|
||||||
//handle the mailer
|
//handle the mailer
|
||||||
|
|
||||||
EntityMailer::dispatch($invitation, 'invoice', $user, $invitation->company);
|
EntitySentMailer::dispatch($invitation, 'invoice', $user, $invitation->company);
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification->method = $methods;
|
$notification->method = $methods;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Listeners\Misc;
|
namespace App\Listeners\Misc;
|
||||||
|
|
||||||
use App\Jobs\Mail\EntityMailer;
|
use App\Jobs\Mail\EntityViewedMailer;
|
||||||
use App\Notifications\Admin\EntityViewedNotification;
|
use App\Notifications\Admin\EntityViewedNotification;
|
||||||
use App\Utils\Traits\Notifications\UserNotifies;
|
use App\Utils\Traits\Notifications\UserNotifies;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -53,11 +53,8 @@ class InvitationViewedListener implements ShouldQueue
|
|||||||
if (($key = array_search('mail', $methods)) !== false) {
|
if (($key = array_search('mail', $methods)) !== false) {
|
||||||
unset($methods[$key]);
|
unset($methods[$key]);
|
||||||
|
|
||||||
//Fire mail notification here!!!
|
EntityViewedMailer::dispatch($invitation, $entity_name, $company_user->user, $invitation->company);
|
||||||
//This allows us better control of how we
|
|
||||||
//handle the mailer
|
|
||||||
|
|
||||||
EntityMailer::dispatch($invitation, 'invoice', $user, $invitation->company);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification->method = $methods;
|
$notification->method = $methods;
|
||||||
|
@ -36,9 +36,9 @@ class EntityNotificationMailer extends Mailable
|
|||||||
*/
|
*/
|
||||||
public function build()
|
public function build()
|
||||||
{
|
{
|
||||||
return $this->from($this->mail_obj->from) //todo
|
return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) //todo
|
||||||
->subject($this->mail_obj->subject)
|
->subject($this->mail_obj->subject)
|
||||||
->markdown($this->mail_obj->markdown, ['data' => $this->mail_obj->data])
|
->markdown($this->mail_obj->markdown, $this->mail_obj->data)
|
||||||
->withSwiftMessage(function ($message) {
|
->withSwiftMessage(function ($message) {
|
||||||
$message->getHeaders()->addTextHeader('Tag', $this->mail_obj->tag);
|
$message->getHeaders()->addTextHeader('Tag', $this->mail_obj->tag);
|
||||||
});
|
});
|
||||||
|
@ -71,7 +71,7 @@ class EntitySentObject
|
|||||||
|
|
||||||
$settings = $this->entity->client->getMergedSettings();
|
$settings = $this->entity->client->getMergedSettings();
|
||||||
|
|
||||||
$data = [
|
return [
|
||||||
'title' => $this->getSubject(),
|
'title' => $this->getSubject(),
|
||||||
'message' => ctrans(
|
'message' => ctrans(
|
||||||
"texts.notification_{$this->entity_type}_sent",
|
"texts.notification_{$this->entity_type}_sent",
|
||||||
@ -87,6 +87,5 @@ class EntitySentObject
|
|||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ trait UserNotifies
|
|||||||
array_push($required_permissions, "all_user_notifications");
|
array_push($required_permissions, "all_user_notifications");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(array_intersect($required_permissions, $notifications->email)) >=1) {
|
if (count(array_intersect($required_permissions, $notifications->email)) >=1 || count(array_intersect($required_permissions, "all_user_notifications")) >=1 || count(array_intersect($required_permissions, "all_notifications")) >=1) {
|
||||||
array_push($notifiable_methods, 'mail');
|
array_push($notifiable_methods, 'mail');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ trait UserNotifies
|
|||||||
array_push($required_permissions, "all_user_notifications");
|
array_push($required_permissions, "all_user_notifications");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(array_intersect($required_permissions, $notifications->email)) >=1) {
|
if (count(array_intersect($required_permissions, $notifications->email)) >=1 || count(array_intersect($required_permissions, "all_user_notifications")) >=1 || count(array_intersect($required_permissions, "all_notifications")) >=1) {
|
||||||
array_push($notifiable_methods, 'mail');
|
array_push($notifiable_methods, 'mail');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user