55use Dacastro4 \LaravelGmail \Services \Message \Mail ;
66use Google_Service_Gmail ;
77use Google_Service_Gmail_Message ;
8+ use Symfony \Component \Mime \Email ;
89use Illuminate \Container \Container ;
910use Illuminate \Mail \Markdown ;
10- use Swift_Attachment ;
11- use Swift_Message ;
1211use 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