@@ -69,7 +69,8 @@ public function sendMessageRequest(Email $message): Message
6969 $ this ->uploadLargeAttachments ($ message , $ draft ->getId ());
7070
7171 // Send the message
72- return $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())) . "/messages/ " . $ draft ->getId () . "/send " )
72+ return $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())->getAddress ()) . "/messages/ " . $ draft ->getId () . "/send " )
73+ ->setReturnType (Message::class)
7374 ->execute ();
7475 }
7576
@@ -81,8 +82,8 @@ public function sendMessageRequest(Email $message): Message
8182
8283 protected function createDraftMessage (Email $ message ): Message
8384 {
84- return $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())) . "/messages " )
85- ->attachBody ($ this ->getBody ($ message , true ))
85+ return $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())-> getAddress () ) . "/messages " )
86+ ->attachBody ($ this ->getBody ($ message , false , true ))
8687 ->setReturnType (Message::class)
8788 ->execute ();
8889 }
@@ -105,7 +106,7 @@ protected function uploadLargeAttachments(Email $message, string $draftId): void
105106 'contentId ' => $ id
106107 ];
107108
108- $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())) . "/messages/ " . $ draftId . "/attachments " )
109+ $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())-> getAddress () ) . "/messages/ " . $ draftId . "/attachments " )
109110 ->attachBody ($ attachmentBody )
110111 ->setReturnType (UploadSession::class)
111112 ->execute ();
@@ -125,7 +126,7 @@ protected function chunkUpload(Email $message, string $draftId, string $fileName
125126 ]
126127 ];
127128
128- $ uploadSession = $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())) . "/messages/ " . $ draftId . "/attachments/createUploadSession " )
129+ $ uploadSession = $ this ->client ->createRequest ("POST " , "/users/ " . (current ($ message ->getFrom ())-> getAddress () ) . "/messages/ " . $ draftId . "/attachments/createUploadSession " )
129130 ->attachBody ($ attachmentMessage )
130131 ->setReturnType (UploadSession::class)
131132 ->execute ();
@@ -167,7 +168,7 @@ protected function chunkUpload(Email $message, string $draftId, string $fileName
167168
168169 protected function getBodySize (Email $ message ): float
169170 {
170- $ messageBody = $ this ->getBody ($ message );
171+ $ messageBody = $ this ->getBody ($ message, true );
171172 $ messageBodyLength = mb_strlen (json_encode ($ messageBody , JSON_NUMERIC_CHECK ), '8bit ' );
172173
173174 return $ messageBodyLength / self ::BYTE_TO_MB ; //byte -> mb
@@ -176,7 +177,7 @@ protected function getBodySize(Email $message): float
176177 /**
177178 * Get body for the message.
178179 */
179- protected function getBody (Email $ message , bool $ hasHugeAttachment = false ): array
180+ protected function getBody (Email $ message , bool $ withAttachments = false , bool $ isDraft = false ): array
180181 {
181182 $ messageData = [
182183 'from ' => [
@@ -196,12 +197,11 @@ protected function getBody(Email $message, bool $hasHugeAttachment = false): arr
196197 ]
197198 ];
198199
199- if (!$ hasHugeAttachment ) {
200+ if (!$ isDraft ) {
200201 $ messageData = ['message ' => $ messageData ];
201202 }
202203
203-
204- if (count ($ message ->getAttachments ()) > 0 ) {
204+ if (count ($ message ->getAttachments ()) > 0 && $ withAttachments ) {
205205 $ attachments = [];
206206 foreach ($ message ->getAttachments () as $ attachment ) {
207207 $ attachments [] = [
0 commit comments