Skip to content

Commit 585c39f

Browse files
committed
� Conflicts: � composer.json
2 parents 464b75e + f11bbd7 commit 585c39f

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"illuminate/routing": "~5.8|^6.0|^7.0|^8.0|^9.0",
2424
"illuminate/session": "~5.8|^6.0|^7.0|^8.0|^9.0",
2525
"illuminate/support": "~5.8|^6.0|^7.0|^8.0|^9.0",
26-
"swiftmailer/swiftmailer": "~5.8|^6.0",
26+
"symfony/mime": "^5.4|^6.0",
2727
"ext-json": "*"
2828
},
2929
"require-dev": {

src/Traits/Replyable.php

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
use Dacastro4\LaravelGmail\Services\Message\Mail;
66
use Google_Service_Gmail;
77
use Google_Service_Gmail_Message;
8+
use Symfony\Component\Mime\Email;
89
use Illuminate\Container\Container;
910
use Illuminate\Mail\Markdown;
10-
use Swift_Attachment;
11-
use Swift_Message;
1211
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1312

1413
/**
@@ -18,7 +17,7 @@ trait Replyable
1817
{
1918
use HasHeaders;
2019

21-
private $swiftMessage;
20+
private $symfonyEmail;
2221

2322
/**
2423
* Gmail optional parameters
@@ -108,7 +107,7 @@ trait Replyable
108107

109108
public function __construct()
110109
{
111-
$this->swiftMessage = new Swift_Message();
110+
$this->symfonyEmail = new Email();
112111
}
113112

114113
/**
@@ -356,7 +355,7 @@ public abstract function getThreadId();
356355
*/
357356
public function setHeader($header, $value)
358357
{
359-
$headers = $this->swiftMessage->getHeaders();
358+
$headers = $this->symfonyEmail->getHeaders();
360359

361360
$headers->addTextHeader($header, $value);
362361

@@ -402,21 +401,45 @@ private function getMessageBody()
402401
{
403402
$body = new Google_Service_Gmail_Message();
404403

405-
$this->swiftMessage
406-
->setSubject($this->subject)
407-
->setFrom($this->from, $this->nameFrom)
408-
->setTo($this->to, $this->nameTo)
409-
->setCc($this->cc, $this->nameCc)
410-
->setBcc($this->bcc, $this->nameBcc)
411-
->setBody($this->message, 'text/html')
412-
->setPriority($this->priority);
413-
414-
foreach ($this->attachments as $file) {
415-
$this->swiftMessage
416-
->attach(Swift_Attachment::fromPath($file));
417-
}
418-
419-
$body->setRaw($this->base64_encode($this->swiftMessage->toString()));
404+
if ($this->from) {
405+
$this->symfonyEmail->from($this->from, ($this->nameFrom ? $this->nameFrom : ''));
406+
}
407+
408+
if ($this->to) {
409+
$this->symfonyEmail->to($this->to, ($this->nameTo ? $this->nameTo : ''));
410+
}
411+
412+
if ($this->cc) {
413+
if (is_array($this->cc)) {
414+
foreach ($this->cc as $emailCc => $nameCc) {
415+
$this->symfonyEmail->addCc($emailCc, $nameCc);
416+
}
417+
} else {
418+
$this->symfonyEmail->cc($this->cc, ($this->nameCc ? $this->nameCc : ''));
419+
}
420+
}
421+
422+
$bccString = "";
423+
if ($this->bcc) {
424+
if (is_array($this->bcc)) {
425+
foreach ($this->bcc as $emailBcc => $nameBcc) {
426+
$bccString .= "Bcc: " . $nameBcc . " <" . $emailBcc . ">\r\n";
427+
}
428+
} else {
429+
$bccString .= "Bcc: " . ($this->nameBcc ? $this->nameBcc . " " : "") . "<" . $this->bcc . ">\r\n";
430+
}
431+
}
432+
433+
$this->symfonyEmail->subject($this->subject)
434+
->html($this->message)
435+
->priority($this->priority)
436+
;
437+
438+
foreach ($this->attachments as $file) {
439+
$this->symfonyEmail->attachFromPath($file);
440+
}
441+
442+
$body->setRaw($this->base64_encode($bccString . $this->symfonyEmail->toString()));
420443

421444
return $body;
422445
}

0 commit comments

Comments
 (0)