diff --git a/docs/v3/msgraph/emails.md b/docs/v3/msgraph/emails.md index 0c0837d..d30085b 100644 --- a/docs/v3/msgraph/emails.md +++ b/docs/v3/msgraph/emails.md @@ -134,6 +134,14 @@ To view an email call **->find($id)** followed by the id of the email. MsGraph::emails()->find($id); ``` +Retrieve the emails using singleValueExtendedProperties. + +```php +MsGraph::emails()->get([ + '\$filter' => 'singleValueExtendedProperties/Any(ep: ep/id eq \'String {00020329-0000-0000-C000-000000000046} Name CustomProperty\' and ep/value eq \'CustomValue\')' +]); +``` + ## Send Email To send an email the format is different to normal calls. The format is to call multiple methods to set the email properties. @@ -172,6 +180,22 @@ MsGraph::emails() ->send() ``` +singleValueExtendedProperties() can be used to add custom properties to the email. + +```php +MsGraph::emails() +->to(['email@domains.com']) +->subject('the subject') +->body('the content') +->singleValueExtendedProperties([ + [ + "id" => "String {00020329-0000-0000-C000-000000000046} Name CustomProperty", + "value" => "CustomValue" + ] +]) +->send() +``` + ## Forward Email To forward to an email call **->forward()** and use **->comment()** instead of **->body()**. @@ -205,7 +229,3 @@ To delete an email call **->delete($id)** followed by the id of the email. ```php MsGraph::emails()->delete($id); ``` - - - - diff --git a/src/Resources/Emails.php b/src/Resources/Emails.php index 860977d..b854ed9 100644 --- a/src/Resources/Emails.php +++ b/src/Resources/Emails.php @@ -27,6 +27,8 @@ class Emails extends MsGraph private array $attachments = []; + private array $singleValueExtendedProperties = []; + public function id(string $id): static { $this->id = $id; @@ -83,6 +85,13 @@ public function attachments(array $attachments): static return $this; } + public function singleValueExtendedProperties(array $singleValueExtendedProperties): static + { + $this->singleValueExtendedProperties = $singleValueExtendedProperties; + + return $this; + } + public function top(string $top): static { $this->top = $top; @@ -246,6 +255,7 @@ protected function prepareEmail(): array $cc = $this->cc; $bcc = $this->bcc; $attachments = $this->attachments; + $singleValueExtendedProperties = $this->singleValueExtendedProperties; $toArray = []; foreach ($to as $email) { @@ -264,14 +274,30 @@ protected function prepareEmail(): array $attachmentArray = []; foreach ($attachments as $file) { + if (array_key_exists('name', $file) && array_key_exists('contentBytes', $file)) { + $attachmentArray[] = [ + '@odata.type' => '#microsoft.graph.fileAttachment', + 'name' => $file['name'], + 'contentBytes' => $file['contentBytes'], + ]; + } else { $path = pathinfo($file); $attachmentArray[] = [ - '@odata.type' => '#microsoft.graph.fileAttachment', - 'name' => $path['basename'], - 'contentType' => mime_content_type($file), - 'contentBytes' => base64_encode(file_get_contents($file)), + '@odata.type' => '#microsoft.graph.fileAttachment', + 'name' => $path['basename'], + 'contentType' => mime_content_type($file), + 'contentBytes' => base64_encode(file_get_contents($file)), ]; + } + } + + $singleValueExtendedPropertiesarray = []; + foreach ($singleValueExtendedProperties as $value) { + $singleValueExtendedPropertiesarray[] = [ + 'id' => $value['id'], + 'value' => $value['value'], + ]; } $envelope = [];