How to subscribe to the sent mail event RRS feed

  • Question

  • Hello,

    In my app, the user create a draft email by using the office365 microsoft graph API, then, I display the edit email page using the weblink inside an iframe.
    But, I want my app to know when this draft is sent to save some information in my database about this email.
    So I search for a service which allow me to do this and I stumble on this:

    But when I try to call this url using my Graph client (PHP) I got a 404 not found error:

    POST HTTP/1.1

    use Microsoft\Graph\Model\Subscription;
    $subscription = new Subscription([
          'Resource'        => '' . $draftEmail->getId(),
          'NotificationURL' => Url::fromRoute('mymodule.mail.notification')->setAbsolute()->toString(TRUE)->getGeneratedUrl(),
          'ChangeType'      => 'Modified',
          'ClientState'     => $draftEmail->getId()
    $office365Client = new Graph();
    $office365Client = $office365Client->createRequest('post', '/me/subscriptions')
    GuzzleHttp\Exception\ClientException: Client error: `POST` resulted in a `404 Not Found` response: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""> <html xml (truncated...) in GuzzleHttp\Exception\RequestException::create() (line 113 of /srv/www/drupal/src/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).

    Can you help me to figure out what is my mistake ?


    Maxime Tual

    Thursday, December 14, 2017 2:58 PM

All replies

  • Wrong documentation:

    I'm now facing this error:

    {"error":true,"context":"Error while calling Microsoft Graph API","message":{"error":{"code":"InvalidRequest",

    "message":"The remote name could not be resolved:","innerError":{"request-id":"169eb423-d454-4159-8346-989b86c2653d","date":"2017-12-14T15:14:31"}}}}

    How can i test this feature in dev mode ?
    Thursday, December 14, 2017 3:27 PM
  • Hello Tual Maxime,

    This forum(Outlook for Developers) is for development issues related to Outlook Object model, and I think your issue is more related to Office 365 Development, so I would move the thread to Office 365 for Developers forum. Thanks for understanding.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, December 15, 2017 7:52 AM
  • @Terry: Ok, thanx you

    @Everybody: I find the way to use this feature in dev mode using ngrok:

    BUT... I got this error now: 

    {"error":true,"context":"Error while calling Microsoft Graph API","message":{"error":{"code":"ExtensionError","message":"Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]","innerError":{"request-id":"a288d197-6139-496f-be1a-e7c68dd19407","date":"2017-12-15T14:34:35"}}}}

    No luck on google and it seems I'm not the first one to get this:


    Friday, December 15, 2017 2:41 PM
  • Found it !

    Here's the working code:
    $subscription = new Subscription([
          'resource'        => "me/mailFolders('Inbox')/messages?filter=id eq %27" . $draftEmail->getId() . '%27', 
          'notificationUrl' => '',
          'changeType'      => 'updated',
          'expirationDateTime' => date(DATE_ISO8601, strtotime('+48 hours'))

    The line which was wrong was:

    'resource' => 'me/messages/' . $draftEmail->getParentFolderId(),

    And i replace it with 

    'resource' => "me/mailFolders('Inbox')/messages?filter=id eq %27" . $draftEmail->getId() . '%27', 

    I found my answer here but in my opinion the resource parameter need to be more documented on graph api documentation and the error message return must specify WHY this is a BadRequest.

    Friday, December 15, 2017 4:15 PM