0
votes

I'm trying to create apps that using Outlook API. The first feature that i want to create is integrate Outlook Mail to my app. But i have problem to reply email, when i try to send email using POST:

POST: https://outlook.office.com/api/v2.0/Users/email/sendmail

{
    "Message": {
        "Subject": "Test",
        "Importance": "Normal",
        "ToRecipients": [{
            "EmailAddress": {
                "Address": "[email protected]",
                "Name": "jais anas"
            }
        }],
        "Body": {
            "ContentType": "HTML",
            "Content": "Bangsaaaaat aneh"
        }
    },
    "SaveToSentItems": "true"
}

the response only return status code 202 accepted the body is empty, then i research and find people who face the same the situation like here

it recommends using PR_SEARCH_KEY. I try to embed PR_SEARCH_KEY like below:

POST https://outlook.office.com/api/v2.0/me/messages

   {
    "Subject": "Test",
        "Importance": "Normal",
        "ToRecipients": [{
            "EmailAddress": {
                "Address": "[email protected]",
                "Name": "jais anas"
            }
        }],
        "Body": {
            "ContentType": "HTML",
            "Content": "ultra aneh"
        },
    "SingleValueExtendedProperties": [
     {
           "PropertyId":"String {66f5a359-4659-4830-9070-00040ec6ac6e} Name Fun",
           "Value":"Food"
     }
  ],
  "IsDraft": false
}

it returns response that what i expected:

 {
    "@odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Messages/$entity",
    "@odata.id": "https://outlook.office.com/api/v2.0/Users('ae679c71-8bf5-4b97-bdf4-77139f637325@b3177487-e927-4ded-ba13-787dec0ebbca')/Messages('AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau_3XsCiAazAAAAAAEPAACfoOdZk3FLQau_3XsCiAazAAEpvIT5AAA=')",
    "@odata.etag": "W/\"CQAAABYAAACfoOdZk3FLQau+3XsCiAazAAEp7BTR\"",
    "Id": "AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau_3XsCiAazAAAAAAEPAACfoOdZk3FLQau_3XsCiAazAAEpvIT5AAA=",
    "CreatedDateTime": "2018-03-12T15:36:30Z",
    "LastModifiedDateTime": "2018-03-12T15:36:31Z",
    "ChangeKey": "CQAAABYAAACfoOdZk3FLQau+3XsCiAazAAEp7BTR",
    "Categories": [],
    "ReceivedDateTime": "2018-03-12T15:36:31Z",
    "SentDateTime": "2018-03-12T15:36:31Z",
    "HasAttachments": false,
    "InternetMessageId": "<PS1PR06MB124320CE100FA9B65B0A1753AAD30@PS1PR06MB1243.apcprd06.prod.outlook.com>",
    "Subject": "Test",
    "BodyPreview": "ultra aneh",
    "Importance": "Normal",
    "ParentFolderId": "AQMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQAuAAAD7hd1QeEpSE_r97u52uiSBwEAn6DnWZNxS0Grvt17AogGswAAAgEPAAAA",
    "ConversationId": "AAQkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQAQAHF_FKARNjtGuOFXHfrijQE=",
    "IsDeliveryReceiptRequested": false,
    "IsReadReceiptRequested": false,
    "IsRead": true,
    "IsDraft": true,
    "WebLink": "https://outlook.office365.com/owa/?ItemID=AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau%2B3XsCiAazAAAAAAEPAACfoOdZk3FLQau%2B3XsCiAazAAEpvIT5AAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
    "InferenceClassification": "Focused",
    "Body": {
        "ContentType": "HTML",
        "Content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nultra aneh\r\n</body>\r\n</html>\r\n"
    },
    "ToRecipients": [
        {
            "EmailAddress": {
                "Name": "jais anas",
                "Address": "[email protected]"
            }
        }
    ],
    "CcRecipients": [],
    "BccRecipients": [],
    "ReplyTo": [],
    "Flag": {
        "FlagStatus": "NotFlagged"
    }
}

Unfortunately that post only create draft does not send email. you can check in part of "IsDraft": true. My question is how to get id of sent items without store message to draft ? i don't see any documentation how to get id from sent email here

1

1 Answers

0
votes

My question is how to get id of sent items without store message to draft

As was mentioned by David in the POST you referenced because a Send is done Async the service won't return the Id to you so you need to search for it based on Id you set in the Sending email. In your SearchKey example you not sending a message your just creating an Item eg you posting it to Messages rather then /email/sendmail .

My suggestion would be rather the using the SearchKey set the InternetMessageId which is a strongly typed property. You need to make sure when you do this that you use a unique Guid in your property values else your breaking the RFC on email if you client doesn't set a unique value. Eg to Send a message and set the InternetMessageId on (which is a valid thing for any client to do)

https://graph.microsoft.com/v1.0/me/sendMail

{
  "message": {
    "subject": "Meet for lunch?",
    "body": {
      "contentType": "Text",
      "content": "The new cafeteria is open."
    },
    "internetMessageId" : "[email protected]",
    "toRecipients": [
      {
        "emailAddress": {
          "address": "[email protected]"
        }
      }
    ]
  }
}

Then to find that message in the Sent Items you use

https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$filter internetMessageId eq '[email protected]'

(I know I'm using the Graph API but it works the same in the other endpoint)