Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Outlook -- Search Messages in a Particular FolderDemonstrates search the messages in a particular Outlook mailbox folder. This uses the OData $filter and $search system query options. See OData System Query Options for general information.
Also see OData URL Conventions for information about $filter, $search and other query options. This example demonstrates the following searches:
This example applies to: Exchange Online | Office 365 | Hotmail.com | Live.com | MSN.com | Outlook.com | Passport.com
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Variant vSbResponse Handle hoSbResponse Handle hoHtFolderMap Variant vSbMap Handle hoSbMap Boolean iSuccess String sFolderId Boolean iSuccess Handle hoJson Handle hoSbExpression Handle hoDt Obj Handle hoDtObj String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // Use your previously obtained access token here: // See the following examples for getting an access token: // Get Microsoft Graph OAuth2 Access Token (Azure AD v2.0 Endpoint). // Get Microsoft Graph OAuth2 Access Token (Azure AD Endpoint). // Refresh Access Token (Azure AD v2.0 Endpoint). // Refresh Access Token (Azure AD Endpoint). Set ComAuthToken Of hoHttp To "MICROSOFT_GRAPH_ACCESS_TOKEN" Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse If (Not(IsComObjectCreated(hoSbResponse))) Begin Send CreateComObject of hoSbResponse End // In this example, we'd like to get the messages in the folder "/Inbox", // but we must specify the corresponding folder_id. The best way to do this is to create // a local map of folderPaths-to-folderIds. // This example does it: Create Outlook Folder Map) Get Create (RefClass(cComChilkatHashtable)) To hoHtFolderMap If (Not(IsComObjectCreated(hoHtFolderMap))) Begin Send CreateComObject of hoHtFolderMap End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbMap If (Not(IsComObjectCreated(hoSbMap))) Begin Send CreateComObject of hoSbMap End Get ComLoadFile Of hoSbMap "qa_data/outlook/folderMap.xml" "utf-8" To iSuccess Get pvComObject of hoSbMap to vSbMap Get ComAddFromXmlSb Of hoHtFolderMap vSbMap To iSuccess // Get the ID for the "/Inbox" folder: Get ComLookupStr Of hoHtFolderMap "/Inbox" To sFolderId Get ComLastMethodSuccess Of hoHtFolderMap To bTemp1 If (bTemp1 <> True) Begin Showln "Folder ID not found" Procedure_Return End Move True To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Set ComEmitCompact Of hoJson To False Get ComSetUrlVar Of hoHttp "folder_id" sFolderId To iSuccess Get ComSetUrlVar Of hoHttp "select" "subject,from" To iSuccess // ----------------------------------------------------------------------------------------------------- // Only return emails from "chilkat.support@gmail.com" Get ComSetUrlVar Of hoHttp "filter" "from/emailAddress/address eq 'chilkat.support@gmail.com'" To iSuccess // To return the full content of each email, omit the "&select=..." part of the URL. Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Only return emails where the subject contains "Amazon" Get ComSetUrlVar Of hoHttp "filter" "contains(subject,'Amazon')" To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Only return emails where the subject starts with "this email" and the from address is support@chilkatsoft.com // (the startswith function is case insensitive) Get ComSetUrlVar Of hoHttp "filter" "startswith(subject,'this email') and (from/emailAddress/address eq 'support@chilkatsoft.com')" To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Only return emails received within the last 24 hours Get Create (RefClass(cComChilkatStringBuilder)) To hoSbExpression If (Not(IsComObjectCreated(hoSbExpression))) Begin Send CreateComObject of hoSbExpression End Get ComAppend Of hoSbExpression "receivedDateTime ge " To iSuccess Get Create (RefClass(cComCkDateTime)) To hoDt If (Not(IsComObjectCreated(hoDt))) Begin Send CreateComObject of hoDt End Get ComSetFromCurrentSystemTime Of hoDt To iSuccess Get ComAddDays Of hoDt -1 To iSuccess Get ComGetAsTimestamp Of hoDt False To sTemp1 Get ComAppend Of hoSbExpression sTemp1 To iSuccess Get ComGetAsString Of hoSbExpression To sTemp1 Get ComSetUrlVar Of hoHttp "filter" sTemp1 To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Only return emails received in October 2016 Get Create (RefClass(cComChilkatDtObj)) To hoDtObj If (Not(IsComObjectCreated(hoDtObj))) Begin Send CreateComObject of hoDtObj End Set ComYear Of hoDtObj To 2016 Set ComMonth Of hoDtObj To 10 Set ComDay Of hoDtObj To 1 Set ComUtc Of hoDtObj To True Get pvComObject of hoDtObj to vDtObj Get ComSetFromDtObj Of hoDt vDtObj To iSuccess Send ComClear To hoSbExpression Get ComAppend Of hoSbExpression "(receivedDateTime ge " To iSuccess Get ComGetAsTimestamp Of hoDt False To sTemp1 Get ComAppend Of hoSbExpression sTemp1 To iSuccess Get ComAppend Of hoSbExpression ") and (receivedDateTime lt " To iSuccess Set ComMonth Of hoDtObj To 11 Get pvComObject of hoDtObj to vDtObj Get ComSetFromDtObj Of hoDt vDtObj To iSuccess Get ComGetAsTimestamp Of hoDt False To sTemp1 Get ComAppend Of hoSbExpression sTemp1 To iSuccess Get ComAppend Of hoSbExpression ")" To iSuccess // This is the expression we just built: (receivedDateTime ge 2016-10-01T00:00:00Z) and (receivedDateTime lt 2016-11-01T00:00:00Z) Get ComGetAsString Of hoSbExpression To sTemp1 Showln sTemp1 Get ComGetAsString Of hoSbExpression To sTemp1 Get ComSetUrlVar Of hoHttp "filter" sTemp1 To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Return unread emails Get ComSetUrlVar Of hoHttp "filter" "isRead eq false" To iSuccess // success = http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",sbResponse); Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Return emails with a plain-text or HTML body containing the phrase "Outlook 365" Get ComSetUrlVar Of hoHttp "filter" "contains(body/content,'Outlook 365')" To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Use the $search query option instead of $filter. // $search is a free-text search over whatever fields the server deems appropriate, such as in the subject, // body, address fields, etc. // Search for the word Amazon Get ComSetUrlVar Of hoHttp "search" "Amazon" To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$search={$search}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // ----------------------------------------------------------------------------------------------------- // Search for chilkatsoft.com // Some chars, such as the "." make it necessary to enclose the search expression in double-quotes. Get ComSetUrlVar Of hoHttp "search" '"chilkatsoft.com"' To iSuccess Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$search={$search}&$select={$select}" vSbResponse To iSuccess Get ComLastStatus Of hoHttp To iTemp1 If ((iSuccess <> True) And (iTemp1 = 0)) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.