Sample code for 30+ languages & platforms
SQL Server

Outlook -- Create Reply Email, Update, and Send

See more Outlook Examples

Creates a reply email in the Drafts folder, updates the reply with information, and then sends the reply.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Use your previously obtained access token here:
    EXEC sp_OASetProperty @http, 'AuthToken', 'MICROSOFT_GRAPH_ACCESS_TOKEN'

    -- This example will search /Inbox for a message that will be replied to.
    -- First we need to get the folder ID for /Inbox.
    -- Then we'll search for messages based on some criteria, and reply to the 1st matching message.
    -- To reply, we'll create the reply message in the Drafts folder, update it with content, and the send.

    -- Get the folder ID for /Inbox from the folder map created by this example 
    DECLARE @htFolderMap int
    EXEC @hr = sp_OACreate 'Chilkat.Hashtable', @htFolderMap OUT

    DECLARE @sbMap int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbMap OUT

    EXEC sp_OAMethod @sbMap, 'LoadFile', @success OUT, 'qa_data/outlook/folderMap.xml', 'utf-8'
    EXEC sp_OAMethod @htFolderMap, 'AddFromXmlSb', @success OUT, @sbMap

    -- Get the ID for the "/Inbox" folder:
    DECLARE @folderId nvarchar(4000)
    EXEC sp_OAMethod @htFolderMap, 'LookupStr', @folderId OUT, '/Inbox'
    EXEC sp_OAGetProperty @htFolderMap, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN

        PRINT 'Folder ID not found'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        RETURN
      END

    SELECT @success = 1
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OASetProperty @json, 'EmitCompact', 0

    -- Search for unread emails in this folder from support@chilkatsoft.com 
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'folder_id', @folderId
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'select', 'id,subject'
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'filter', '(isRead eq false) and (from/emailAddress/address eq ''support@chilkatsoft.com'')'

    DECLARE @sbResponse int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponse OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}', @sbResponse
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        RETURN
      END

    EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbResponse
    -- Show the results..
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    EXEC sp_OAMethod @json, 'SizeOfArray', @iTmp0 OUT, 'value'
    IF @iTmp0 = 0
      BEGIN

        PRINT 'Empty result set.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        RETURN
      END

    -- Sample results:

    -- {
    --   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('me')/mailFolders('AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAgEMAAAA')/messages(id,subject)",
    --   "value": [
    --     {
    --       "@odata.etag": "W/\"CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADOpwfq\"",
    --       "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEMAAAA5_vF7TKKdE6bGCRqXyl2PQAAAM6Jj1wAAAA=",
    --       "subject": "This email contains a PDF attachment"
    --     },
    --     {
    --       "@odata.etag": "W/\"CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADOpwfs\"",
    --       "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEMAAAA5_vF7TKKdE6bGCRqXyl2PQAAAM6Jj14AAAA=",
    --       "subject": "This email has the word Amazon in the subject.."
    --     }
    --   ]
    -- }

    -- We'll create a reply for the 1st message in the result set.
    -- We'll need the message existing id.

    DECLARE @existingMsgId nvarchar(4000)
    EXEC sp_OAMethod @json, 'StringOf', @existingMsgId OUT, 'value[0].id'

    -- To create a reply, send a request such as the following:

    -- 	POST https://graph.microsoft.com/v1.0/me/messages/{id}/createReply
    -- 	Content-type: application/json
    -- 	Content-length: 248
    -- 
    -- 	{
    -- 	  "comment": "comment-value"
    -- 	}

    DECLARE @jsonRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonRequestBody OUT

    EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'comment', 'This is a comment'

    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'message_id', @existingMsgId

    -- Create the reply in the Drafts folder:
    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'POST', 'https://graph.microsoft.com/v1.0/me/messages/{$message_id}/createReply', @jsonRequestBody, 'application/json', @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END

    -- A 201 response indicates success.
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 = 201
      BEGIN

        PRINT 'Created reply draft.'
        SELECT @success = 1
      END
    ELSE
      BEGIN

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        PRINT 'Response status code = ' + @iTmp0

        PRINT 'Failed to create reply draft.'
        SELECT @success = 0
      END

    -- Show the response in both cases..
    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonResponse OUT

    EXEC sp_OASetProperty @jsonResponse, 'EmitCompact', 0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @sTmp0
    EXEC sp_OAMethod @jsonResponse, 'Emit', @sTmp0 OUT
    PRINT @sTmp0
    IF @success = 0
      BEGIN
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @jsonResponse
        RETURN
      END

    -- ----------------------------------------------
    -- Get the message id of the newly created reply.
    DECLARE @replyMsgId nvarchar(4000)
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @replyMsgId OUT, 'id'

    -- Update the message with new text in the body..
    -- Send an HTTP PATCH request that looks something like this:
    -- Only send the message parts that are changing.

    -- 	PATCH https://graph.microsoft.com/v1.0/me/messages/{reply_message_id}
    -- 	Content-type: application/json
    -- 	Content-length: 248
    -- 
    -- 	{
    -- 	  "subject": "subject-value",
    -- 	  "body": {
    -- 	    "contentType": "html",
    -- 	    "content": "updated HTML goes here"
    -- 	  },
    -- 	  "inferenceClassification": "other"
    -- 	}

    DECLARE @jsonPatch int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonPatch OUT

    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'body.contentType', 'html'

    -- The reply email that Outlook created will contain the original message under a horizontal rule.
    -- The body.content should contain this substring:  "<body bgcolor=\"#FFFFFF\">\r\n<hr "
    -- We're going to insert our reply after the body tag, and before the hr tag.
    DECLARE @sbHtml int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbHtml OUT

    EXEC sp_OAMethod @jsonResponse, 'StringOfSb', @success OUT, 'body.content', @sbHtml
    -- Insert the response HTML in the reply HTML body.
    DECLARE @numReplaced int
    EXEC sp_OAMethod @sbHtml, 'ReplaceBetween', @numReplaced OUT, '<body bgcolor="#FFFFFF">', '<hr ', CHAR(13) + CHAR(10), '<p>This is my response.</p>'
    IF @numReplaced <> 1
      BEGIN

        PRINT 'Something is amiss!'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @jsonResponse
        EXEC @hr = sp_OADestroy @jsonPatch
        EXEC @hr = sp_OADestroy @sbHtml
        RETURN
      END
    EXEC sp_OAMethod @sbHtml, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'body.content', @sTmp0

    -- Add additional CC, BCC, or TO recipients like this:
    DECLARE @numToRecipients int
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @numToRecipients OUT, 'toRecipients'
    DECLARE @i int
    SELECT @i = 0
    -- Copy existing TO recipients.
    WHILE @i < @numToRecipients
      BEGIN
        EXEC sp_OASetProperty @jsonPatch, 'I', @i
        EXEC sp_OASetProperty @jsonResponse, 'I', @i
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sTmp0 OUT, 'toRecipients[i].emailAddress.name'
        EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'toRecipients[i].emailAddress.name', @sTmp0
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sTmp0 OUT, 'toRecipients[i].emailAddress.address'
        EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'toRecipients[i].emailAddress.address', @sTmp0
        SELECT @i = @i + 1
      END
    -- Add an additional TO recipient.
    EXEC sp_OASetProperty @jsonPatch, 'I', @numToRecipients
    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'toRecipients[i].emailAddress.name', 'Chilkat'
    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'toRecipients[i].emailAddress.address', 'admin@chilkat.io'

    DECLARE @numCcRecipients int
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @numCcRecipients OUT, 'ccRecipients'
    SELECT @i = 0
    -- Copy existing CC recipients.
    WHILE @i < @numCcRecipients
      BEGIN
        EXEC sp_OASetProperty @jsonPatch, 'I', @i
        EXEC sp_OASetProperty @jsonResponse, 'I', @i
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sTmp0 OUT, 'ccRecipients[i].emailAddress.name'
        EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'ccRecipients[i].emailAddress.name', @sTmp0
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sTmp0 OUT, 'ccRecipients[i].emailAddress.address'
        EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'ccRecipients[i].emailAddress.address', @sTmp0
        SELECT @i = @i + 1
      END
    -- Add an additional CC recipient.
    EXEC sp_OASetProperty @jsonPatch, 'I', @numCcRecipients
    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'ccRecipients[i].emailAddress.name', 'Chilkat GMail'
    EXEC sp_OAMethod @jsonPatch, 'UpdateString', @success OUT, 'ccRecipients[i].emailAddress.address', 'chilkat.support@gmail.com'

    EXEC sp_OASetProperty @jsonPatch, 'EmitCompact', 0
    EXEC sp_OAMethod @jsonPatch, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'message_id', @replyMsgId
    EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'PATCH', 'https://graph.microsoft.com/v1.0/me/messages/{$message_id}', @jsonPatch, 'application/json', @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @jsonResponse
        EXEC @hr = sp_OADestroy @jsonPatch
        EXEC @hr = sp_OADestroy @sbHtml
        RETURN
      END

    -- A 200 response indicates success.
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 = 200
      BEGIN

        PRINT 'Patched the reply draft.'
        SELECT @success = 1
      END
    ELSE
      BEGIN

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        PRINT 'Response status code = ' + @iTmp0

        PRINT 'Failed to patch the reply draft.'
        SELECT @success = 0
      END

    -- Show the response in both cases..
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @sTmp0
    EXEC sp_OAMethod @jsonResponse, 'Emit', @sTmp0 OUT
    PRINT @sTmp0
    IF @success = 0
      BEGIN
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @jsonResponse
        EXEC @hr = sp_OADestroy @jsonPatch
        EXEC @hr = sp_OADestroy @sbHtml
        RETURN
      END

    -- ---------------------------------------------------------------------
    -- OK, let's send the reply email...
    -- To send, POST with an empty request body:
    -- POST https://graph.microsoft.com/v1.0/me/messages/{id}/send
    EXEC sp_OAMethod @http, 'HttpStr', @success OUT, 'POST', 'https://graph.microsoft.com/v1.0/me/messages/{$message_id}/send', '', '', '', @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @htFolderMap
        EXEC @hr = sp_OADestroy @sbMap
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponse
        EXEC @hr = sp_OADestroy @jsonRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @jsonResponse
        EXEC @hr = sp_OADestroy @jsonPatch
        EXEC @hr = sp_OADestroy @sbHtml
        RETURN
      END

    -- A 202 response indicates success.
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 = 202
      BEGIN

        PRINT 'Sent the email reply.'
        -- If the status code was 202, there is no response body.
      END
    ELSE
      BEGIN

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        PRINT 'Response status code = ' + @iTmp0

        PRINT 'Failed to send the email reply.'
        EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
        EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @sTmp0
        EXEC sp_OAMethod @jsonResponse, 'Emit', @sTmp0 OUT
        PRINT @sTmp0
      END


    PRINT 'Finished.'

    -- -----------------------------------------------------------------------
    -- A sample successful JSON response for the createReply looks like this:

    -- 	{
    -- 	  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#message",
    -- 	  "@odata.type": "#microsoft.graph.message",
    -- 	  "@odata.etag": "W/\"CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADQAwR4\"",
    -- 	  "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEPAAAA5_vF7TKKdE6bGCRqXyl2PQAAAM-lQbAAAAA=",
    -- 	  "createdDateTime": "2017-06-01T14:31:56Z",
    -- 	  "lastModifiedDateTime": "2017-06-01T14:31:56Z",
    -- 	  "changeKey": "CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADQAwR4",
    -- 	  "categories": [
    -- 	  ],
    -- 	  "receivedDateTime": "2017-06-01T14:31:56Z",
    -- 	  "sentDateTime": "2017-06-01T14:31:56Z",
    -- 	  "hasAttachments": false,
    -- 	  "internetMessageId": "<SN1PR20MB0461AF40FC899A8462536F04E6F60@SN1PR20MB0461.namprd20.prod.outlook.com>",
    -- 	  "subject": "RE: This email contains a PDF attachment",
    -- 	  "bodyPreview": "________________________________\r\nFrom: Chilkat Software <support@chilkatsoft.com>\r\nSent: Tuesday, May 30, 2017 10:58:56 PM\r\nTo: chilkatsoft@outlook.com\r\nSubject: This email contains a PDF attachment\r\n\r\nThis email contains a PDF attachment\r\n--\r\nBest Regar",
    -- 	  "importance": "normal",
    -- 	  "parentFolderId": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAgEPAAAA",
    -- 	  "conversationId": "AQQkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAQAMMaWY-CWmVOqNKt-NiVhkU=",
    -- 	  "isDeliveryReceiptRequested": false,
    -- 	  "isReadReceiptRequested": false,
    -- 	  "isRead": true,
    -- 	  "isDraft": true,
    -- 	  "webLink": "https://outlook.live.com/owa/?ItemID=AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5%2BvF7TKKdE6bGCRqXyl2PQAAAgEPAAAA5%2BvF7TKKdE6bGCRqXyl2PQAAAM%2FlQbAAAAA%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<meta content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body bgcolor=\"#FFFFFF\">\r\n<hr tabindex=\"-1\" style=\"display:inline-block; width:98%\"> ... </html>\r\n"
    -- 	  },
    -- 	  "sender": {
    -- 	    "emailAddress": {
    -- 	      "name": "Matt Smith",
    -- 	      "address": "chilkatsoft@outlook.com"
    -- 	    }
    -- 	  },
    -- 	  "from": {
    -- 	    "emailAddress": {
    -- 	      "name": "Matt Smith",
    -- 	      "address": "chilkatsoft@outlook.com"
    -- 	    }
    -- 	  },
    -- 	  "toRecipients": [
    -- 	    {
    -- 	      "emailAddress": {
    -- 	        "name": "Chilkat Software",
    -- 	        "address": "support@chilkatsoft.com"
    -- 	      }
    -- 	    }
    -- 	  ],
    -- 	  "ccRecipients": [
    -- 	  ],
    -- 	  "bccRecipients": [
    -- 	  ],
    -- 	  "replyTo": [
    -- 	  ]
    -- 	}
    -- 

    -- -----------------------------------------------------------------------
    -- A sample successful PATCH JSON response looks like this:

    -- 	{
    -- 	  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/messages/$entity",
    -- 	  "@odata.etag": "W/\"CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADQAwSA\"",
    -- 	  "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEPAAAA5_vF7TKKdE6bGCRqXyl2PQAAAM-lQbMAAAA=",
    -- 	  "createdDateTime": "2017-06-01T15:18:14Z",
    -- 	  "lastModifiedDateTime": "2017-06-01T15:18:17Z",
    -- 	  "changeKey": "CQAAABYAAADn68XtMop0TpsYJGpfKXY9AADQAwSA",
    -- 	  "categories": [
    -- 	  ],
    -- 	  "receivedDateTime": "2017-06-01T15:18:15Z",
    -- 	  "sentDateTime": "2017-06-01T15:18:15Z",
    -- 	  "hasAttachments": false,
    -- 	  "internetMessageId": "<SN1PR20MB046138C4A26051200764FE38E6F60@SN1PR20MB0461.namprd20.prod.outlook.com>",
    -- 	  "subject": "RE: This email has the word Amazon in the subject..",
    -- 	  "bodyPreview": "This is my response.\r\n\r\n________________________________\r\nFrom: Chilkat Software <support@chilkatsoft.com>\r\nSent: Tuesday, May 30, 2017 11:40:01 PM\r\nTo: Chilkat Software\r\nSubject: This email has the word Amazon in the subject..\r\n\r\nThis email has the word ",
    -- 	  "importance": "normal",
    -- 	  "parentFolderId": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAgEPAAAA",
    -- 	  "conversationId": "AQQkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAQAE64PfPP1n1IhU4YasnNN0Q=",
    -- 	  "isDeliveryReceiptRequested": false,
    -- 	  "isReadReceiptRequested": false,
    -- 	  "isRead": true,
    -- 	  "isDraft": true,
    -- 	  "webLink": "https://outlook.live.com/owa/?ItemID=AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5%2BvF7TKKdE6bGCRqXyl2PQAAAgEPAAAA5%2BvF7TKKdE6bGCRqXyl2PQAAAM%2FlQbMAAAA%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<meta content=\"text/html; charset=us-ascii\">\r\n<meta content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body bgcolor=\"#FFFFFF\">\r\n<p>This is my response.</p>\r\n<hr tabindex=\"-1\" style=\"display:inline-block; width:98%\">\r\n<div id=\"divRplyFwdMsg\" dir=\"ltr\"><font face=\"Calibri, sans-serif\" color=\"#000000\" style=\"font-size:11pt\"><b>From:</b> Chilkat Software &lt;support@chilkatsoft.com&gt;<br>\r\n<b>Sent:</b> Tuesday, May 30, 2017 11:40:01 PM<br>\r\n<b>To:</b> Chilkat Software<br>\r\n<b>Subject:</b> This email has the word Amazon in the subject..</font>\r\n<div>&nbsp;</div>\r\n</div>\r\n<div><font face=\"Calibri\">This email has the word Amazon in the subject..</font><br>\r\n<div class=\"moz-signature\">-- <br>\r\nBest Regards,<br>\r\nMatt Smith<br>\r\nChilkat Software, Inc.<br>\r\n<p><a href=\"https://twitter.com/chilkatsoft\">Follow Chilkat on Twitter</a> </p>\r\n</div>\r\n</div>\r\n</body>\r\n</html>\r\n"
    -- 	  },
    -- 	  "sender": {
    -- 	    "emailAddress": {
    -- 	      "name": "Matt Smith",
    -- 	      "address": "chilkatsoft@outlook.com"
    -- 	    }
    -- 	  },
    -- 	  "from": {
    -- 	    "emailAddress": {
    -- 	      "name": "Matt Smith",
    -- 	      "address": "chilkatsoft@outlook.com"
    -- 	    }
    -- 	  },
    -- 	  "toRecipients": [
    -- 	    {
    -- 	      "emailAddress": {
    -- 	        "name": "Chilkat Software",
    -- 	        "address": "support@chilkatsoft.com"
    -- 	      }
    -- 	    }
    -- 	  ],
    -- 	  "ccRecipients": [
    -- 	  ],
    -- 	  "bccRecipients": [
    -- 	  ],
    -- 	  "replyTo": [
    -- 	  ]
    -- 	}

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @htFolderMap
    EXEC @hr = sp_OADestroy @sbMap
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponse
    EXEC @hr = sp_OADestroy @jsonRequestBody
    EXEC @hr = sp_OADestroy @resp
    EXEC @hr = sp_OADestroy @jsonResponse
    EXEC @hr = sp_OADestroy @jsonPatch
    EXEC @hr = sp_OADestroy @sbHtml


END
GO