1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/app/Helpers/Mail/GmailTransport.php

95 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Mail;
2022-06-24 15:49:22 +02:00
use App\Models\User;
2021-02-11 04:43:48 +01:00
use App\Utils\TempFile;
2021-02-17 01:25:30 +01:00
use Dacastro4\LaravelGmail\Facade\LaravelGmail;
use Dacastro4\LaravelGmail\Services\Message\Mail;
2022-06-24 15:49:22 +02:00
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
use Symfony\Component\Mime\MessageConverter;
2022-07-06 02:08:09 +02:00
/**
* GmailTransport.
*/
2022-06-24 15:49:22 +02:00
class GmailTransport extends AbstractTransport
{
/**
* The Gmail instance.
*
2020-10-28 11:10:49 +01:00
* @var Mail
*/
2022-06-24 15:49:22 +02:00
public $gmail;
public $body;
/**
* Create a new Gmail transport instance.
*
2020-10-28 11:10:49 +01:00
* @param Mail $gmail
* @param string $token
*/
2022-06-24 15:49:22 +02:00
public function __construct()
{
2022-06-24 15:49:22 +02:00
parent::__construct();
2022-07-05 08:15:46 +02:00
2022-06-24 15:49:22 +02:00
$this->gmail = new Mail;
$this->body = new \Google\Service\Gmail\Message();
}
2022-06-24 15:49:22 +02:00
protected function doSend(SentMessage $message): void
{
2022-06-24 15:49:22 +02:00
nlog("in Do Send");
$message = MessageConverter::toEmail($message->getOriginalMessage());
2022-06-24 23:02:59 +02:00
$token = $message->getHeaders()->get('GmailToken')->getValue();
2022-07-06 02:08:09 +02:00
$message->getHeaders()->remove('GmailToken');
2022-06-24 15:49:22 +02:00
// $this->beforeSendPerformed($message);
2022-07-06 02:08:09 +02:00
2021-02-17 01:25:30 +01:00
$this->gmail->using($token);
2022-06-24 16:36:59 +02:00
$this->gmail->to($message->getTo()[0]->getAddress(), $message->getTo()[0]->getName());
$this->gmail->from($message->getFrom()[0]->getAddress(), $message->getFrom()[0]->getName());
2022-06-24 16:27:29 +02:00
2022-06-24 15:49:22 +02:00
$this->gmail->subject($message->getSubject());
$this->gmail->message($message->getHtmlBody());
$this->gmail->cc($message->getCc());
2021-06-23 07:13:33 +02:00
2022-06-24 15:49:22 +02:00
if(is_array($message->getBcc()))
2021-06-23 07:13:33 +02:00
$this->gmail->bcc(array_keys($message->getBcc()));
2022-06-24 15:49:22 +02:00
2022-06-24 16:11:10 +02:00
foreach ($message->getAttachments() as $child)
{
2022-06-24 15:49:22 +02:00
2022-06-24 16:11:10 +02:00
if($child->getContentType() != 'text/plain')
{
2022-06-24 15:49:22 +02:00
2022-06-24 16:27:29 +02:00
$this->gmail->attach(TempFile::filePath($child->getBody(), $child->getName() ));
2022-06-24 15:49:22 +02:00
2022-06-24 16:11:10 +02:00
}
2022-06-24 15:49:22 +02:00
2022-06-24 16:11:10 +02:00
}
2022-06-24 15:49:22 +02:00
$this->gmail->send();
// $this->gmail->service->users_messages->send('me', $this->body,[]);
}
2022-06-24 15:49:22 +02:00
public function __toString(): string
{
return 'gmail';
}
}