Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PowerBuilder Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) Outlook -- Search Messages in a Particular Folder

Demonstrates 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:

  • Find emails from a particular email address.
  • Find emails where the subject contains a particular word or phrase.
  • Using an "AND" expression.
  • Find emails received in the last 24 hours.
  • Find emails received in October 2016
  • Find unread emails
  • Find emails containing a particular phrase in the body.
  • Free-text search of a keyword or phrase.
  • Free-text search of an email address.
Note: This example requires Chilkat v9.5.0.68 or greater.

This example applies to: Exchange Online | Office 365 | Hotmail.com | Live.com | MSN.com | Outlook.com | Passport.com

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Http
oleobject loo_SbResponse
oleobject loo_HtFolderMap
oleobject loo_SbMap
string ls_FolderId
integer li_Success
oleobject loo_Json
oleobject loo_SbExpression
oleobject loo_Dt
oleobject loo_DtObj

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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).

loo_Http.AuthToken = "MICROSOFT_GRAPH_ACCESS_TOKEN"

loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

// 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)
loo_HtFolderMap = create oleobject
li_rc = loo_HtFolderMap.ConnectToNewObject("Chilkat_9_5_0.Hashtable")

loo_SbMap = create oleobject
li_rc = loo_SbMap.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbMap.LoadFile("qa_data/outlook/folderMap.xml","utf-8")
loo_HtFolderMap.AddFromXmlSb(loo_SbMap)

// Get the ID for the "/Inbox" folder:
ls_FolderId = loo_HtFolderMap.LookupStr("/Inbox")
if loo_HtFolderMap.LastMethodSuccess <> 1 then
    Write-Debug "Folder ID not found"
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    return
end if

li_Success = 1
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.EmitCompact = 0

loo_Http.SetUrlVar("folder_id",ls_FolderId)
loo_Http.SetUrlVar("select","subject,from")

// -----------------------------------------------------------------------------------------------------
// Only return emails from "chilkat.support@gmail.com"
loo_Http.SetUrlVar("filter","from/emailAddress/address eq 'chilkat.support@gmail.com'")

// To return the full content of each email, omit the "&select=..." part of the URL.
li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Only return emails where the subject contains "Amazon"
loo_Http.SetUrlVar("filter","contains(subject,'Amazon')")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Only return emails where the subject starts with "this email" and the from address is support@chilkatsoft.com
// (the startswith function is case insensitive)
loo_Http.SetUrlVar("filter","startswith(subject,'this email') and (from/emailAddress/address eq 'support@chilkatsoft.com')")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Only return emails received within the last 24 hours
loo_SbExpression = create oleobject
li_rc = loo_SbExpression.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbExpression.Append("receivedDateTime ge ")
loo_Dt = create oleobject
li_rc = loo_Dt.ConnectToNewObject("Chilkat_9_5_0.CkDateTime")

loo_Dt.SetFromCurrentSystemTime()
loo_Dt.AddDays(-1)
loo_SbExpression.Append(loo_Dt.GetAsTimestamp(0))

loo_Http.SetUrlVar("filter",loo_SbExpression.GetAsString())

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Only return emails received in October 2016
loo_DtObj = create oleobject
li_rc = loo_DtObj.ConnectToNewObject("Chilkat_9_5_0.DtObj")

loo_DtObj.Year = 2016
loo_DtObj.Month = 10
loo_DtObj.Day = 1
loo_DtObj.Utc = 1
loo_Dt.SetFromDtObj(loo_DtObj)

loo_SbExpression.Clear()
loo_SbExpression.Append("(receivedDateTime ge ")
loo_SbExpression.Append(loo_Dt.GetAsTimestamp(0))
loo_SbExpression.Append(") and (receivedDateTime lt ")
loo_DtObj.Month = 11
loo_Dt.SetFromDtObj(loo_DtObj)
loo_SbExpression.Append(loo_Dt.GetAsTimestamp(0))
loo_SbExpression.Append(")")

// This is the expression we just built:  (receivedDateTime ge 2016-10-01T00:00:00Z) and (receivedDateTime lt 2016-11-01T00:00:00Z)
Write-Debug loo_SbExpression.GetAsString()

loo_Http.SetUrlVar("filter",loo_SbExpression.GetAsString())

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    destroy loo_DtObj
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Return unread emails
loo_Http.SetUrlVar("filter","isRead eq false")

// success = http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",sbResponse);
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    destroy loo_DtObj
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Return emails with a plain-text or HTML body containing the phrase "Outlook 365"
loo_Http.SetUrlVar("filter","contains(body/content,'Office 365')")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$filter={$filter}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    destroy loo_DtObj
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// 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
loo_Http.SetUrlVar("search","Amazon")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$search={$search}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    destroy loo_DtObj
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()

// -----------------------------------------------------------------------------------------------------
// Search for chilkatsoft.com
// Some chars, such as the "." make it necessary to enclose the search expression in double-quotes.
loo_Http.SetUrlVar("search","\"chilkatsoft.com\"")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/messages?$search={$search}&$select={$select}",loo_SbResponse)
if (li_Success <> 1) AND (loo_Http.LastStatus = 0) then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    destroy loo_HtFolderMap
    destroy loo_SbMap
    destroy loo_Json
    destroy loo_SbExpression
    destroy loo_Dt
    destroy loo_DtObj
    return
end if

loo_Json.LoadSb(loo_SbResponse)
Write-Debug loo_Json.Emit()


destroy loo_Http
destroy loo_SbResponse
destroy loo_HtFolderMap
destroy loo_SbMap
destroy loo_Json
destroy loo_SbExpression
destroy loo_Dt
destroy loo_DtObj

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.