Skip to content

Commit a7b516f

Browse files
committed
Merge branch 'master' of github.com:dcblogdev/laravel-microsoft-graph
2 parents b6d1cf9 + be0aea9 commit a7b516f

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

docs/v3/msgraph/emails.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ To view an email call **->find($id)** followed by the id of the email.
134134
MsGraph::emails()->find($id);
135135
```
136136

137+
Retrieve the emails using singleValueExtendedProperties.
138+
139+
```php
140+
MsGraph::emails()->get([
141+
'\$filter' => 'singleValueExtendedProperties/Any(ep: ep/id eq \'String {00020329-0000-0000-C000-000000000046} Name CustomProperty\' and ep/value eq \'CustomValue\')'
142+
]);
143+
```
144+
137145
## Send Email
138146

139147
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()
172180
->send()
173181
```
174182

183+
singleValueExtendedProperties() can be used to add custom properties to the email.
184+
185+
```php
186+
MsGraph::emails()
187+
->to(['email@domains.com'])
188+
->subject('the subject')
189+
->body('the content')
190+
->singleValueExtendedProperties([
191+
[
192+
"id" => "String {00020329-0000-0000-C000-000000000046} Name CustomProperty",
193+
"value" => "CustomValue"
194+
]
195+
])
196+
->send()
197+
```
198+
175199
## Forward Email
176200

177201
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.
205229
```php
206230
MsGraph::emails()->delete($id);
207231
```
208-
209-
210-
211-

src/Resources/Emails.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Emails extends MsGraph
2727

2828
private array $attachments = [];
2929

30+
private array $singleValueExtendedProperties = [];
31+
3032
public function id(string $id): static
3133
{
3234
$this->id = $id;
@@ -83,6 +85,13 @@ public function attachments(array $attachments): static
8385
return $this;
8486
}
8587

88+
public function singleValueExtendedProperties(array $singleValueExtendedProperties): static
89+
{
90+
$this->singleValueExtendedProperties = $singleValueExtendedProperties;
91+
92+
return $this;
93+
}
94+
8695
public function top(string $top): static
8796
{
8897
$this->top = $top;
@@ -246,6 +255,7 @@ protected function prepareEmail(): array
246255
$cc = $this->cc;
247256
$bcc = $this->bcc;
248257
$attachments = $this->attachments;
258+
$singleValueExtendedProperties = $this->singleValueExtendedProperties;
249259

250260
$toArray = [];
251261
foreach ($to as $email) {
@@ -264,14 +274,30 @@ protected function prepareEmail(): array
264274

265275
$attachmentArray = [];
266276
foreach ($attachments as $file) {
277+
if (array_key_exists('name', $file) && array_key_exists('contentBytes', $file)) {
278+
$attachmentArray[] = [
279+
'@odata.type' => '#microsoft.graph.fileAttachment',
280+
'name' => $file['name'],
281+
'contentBytes' => $file['contentBytes'],
282+
];
283+
} else {
267284
$path = pathinfo($file);
268285

269286
$attachmentArray[] = [
270-
'@odata.type' => '#microsoft.graph.fileAttachment',
271-
'name' => $path['basename'],
272-
'contentType' => mime_content_type($file),
273-
'contentBytes' => base64_encode(file_get_contents($file)),
287+
'@odata.type' => '#microsoft.graph.fileAttachment',
288+
'name' => $path['basename'],
289+
'contentType' => mime_content_type($file),
290+
'contentBytes' => base64_encode(file_get_contents($file)),
274291
];
292+
}
293+
}
294+
295+
$singleValueExtendedPropertiesarray = [];
296+
foreach ($singleValueExtendedProperties as $value) {
297+
$singleValueExtendedPropertiesarray[] = [
298+
'id' => $value['id'],
299+
'value' => $value['value'],
300+
];
275301
}
276302

277303
$envelope = [];

0 commit comments

Comments
 (0)