1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Helpers/Mail/GmailTransport.php

80 lines
1.9 KiB
PHP
Raw Normal View History

<?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\Helpers\Mail;
use Dacastro4\LaravelGmail\Services\Message\Mail;
use Illuminate\Mail\Transport\Transport;
2019-12-04 06:26:07 +01:00
use Swift_Mime_SimpleMessage;
/**
* GmailTransport.
*/
class GmailTransport extends Transport
{
/**
* The Gmail instance.
*
2020-10-28 11:10:49 +01:00
* @var Mail
*/
protected $gmail;
/**
* The GMail OAuth Token.
* @var string token
*/
protected $token;
/**
* Create a new Gmail transport instance.
*
2020-10-28 11:10:49 +01:00
* @param Mail $gmail
* @param string $token
*/
public function __construct(Mail $gmail, string $token)
{
$this->gmail = $gmail;
2019-12-04 06:26:07 +01:00
$this->token = $token;
}
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
/*We should nest the token in the message and then discard it as needed*/
$this->beforeSendPerformed($message);
$this->gmail->using($this->token);
$this->gmail->to($message->getTo());
$this->gmail->from($message->getFrom());
$this->gmail->subject($message->getSubject());
2019-12-04 06:26:07 +01:00
$this->gmail->message($message->getBody());
//$this->gmail->message($message->toString());
$this->gmail->cc($message->getCc());
$this->gmail->bcc($message->getBcc());
2021-02-11 00:38:42 +01:00
foreach ($message->getChildren() as $child) {
nlog("trying to attach");
nlog($child->getContentType());
2021-02-11 00:55:08 +01:00
if($child->getContentType() != 'text/plain')
2021-02-11 00:38:42 +01:00
$this->gmail->attach($child);
2021-02-11 00:38:42 +01:00
} //todo this should 'just work'
$this->gmail->send();
$this->sendPerformed($message);
return $this->numberOfRecipients($message);
}
}