msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

How to read EML attachment inside a message

Open francescodiperna opened this issue 2 years ago • 2 comments

Hi, can anyone give me an example hot to read the content of EML attachment in MIME format?

Kind regards

francescodiperna avatar Jun 21 '22 13:06 francescodiperna

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

basementmedia2 avatar Jun 29 '22 13:06 basementmedia2

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

francescodiperna avatar Jul 04 '22 07:07 francescodiperna

Closing this to be tracked under #511

Ndiritu avatar Jan 31 '24 17:01 Ndiritu