msgraph-sdk-php
msgraph-sdk-php copied to clipboard
How to read EML attachment inside a message
Hi, can anyone give me an example hot to read the content of EML attachment in MIME format?
Kind regards
Hi,
i'm also a beginner, but i read emails this way:
require_once __DIR__ . '/vendor/autoload.php'; // your path to autoload.php
// Include the Microsoft Graph classes
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$tenantId="your tenant id";
$clientId="your client id";
$clientSecret="your secret";
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$accessToken = $token->access_token;
$graph = new Graph();
$graph->setAccessToken($accessToken);
// ID of Email must be known
$email = $graph->createRequest("GET", "[email protected]/mailfolders/inbox/messages/ID_of_Email)
->setReturnType(Model\Message::class)
->execute();
// Output response array
print_r($email);
Hope that helps. As said, i am also still a beginner
Best wishes Daniel
Thanks Daniel, but I'm using the endpoint that starts with "/users/" because I'm reading a set of mailboxes of a tenant. So, I cannot use you code.
Bye
Closing this to be tracked under #511