Get all messages with search condition(s)
This example shows how to use search condition(s) to filter mails for search operation. For more examples refer https://support.google.com/mail/answer/7190
The ZappySys API Driver is a user-friendly interface designed to facilitate the seamless integration of various applications with the Gmail API. With its intuitive design and robust functionality, the ZappySys API Driver simplifies the process of configuring specific API endpoints to efficiently read or write data from Gmail.
Following examples shows how to Get all messages with search condition(s) from Gmail using ZappySys API Driver. You can explore additional SQL examples for the Azure DevOps Connector.
SELECT *
FROM Messages
--Use WITH clause --OR-- Key column(s) in WHERE clause. If you use Id in Where clause then Search parameter is ignored
--WHERE [Id] = '18fb7747b0136726'
WITH(
Search='after:<<yearstart+1d|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1d|~|yyyy/MM/dd,FUN_TO_DATE>>' --search for mail sent between some dates (after year start plus one day and before yesterday (i.e. today-1d))
-- Search='after:2024/01/31 before:2024/05/25' --use of static date
--for more examples refer https://support.google.com/mail/answer/7190
-- Search='FREE PRODUCT' --search example for=> has words anywhere in the subject or body
-- Search='"FREE PRODUCT"' --search example for=> has exact phrase anywhere in the subject or body
-- Search='subject:FREE PRODUCT' --search example for=> has subject (contains any word)
-- Search='subject:(FREE PRODUCT)' --search example for => has subject (contains exact phrase)
-- Search='Rfc822msgid:<008601dae391$fda78bf0$f8f6a3d0$@zappysys.com>' --search example for => Search by Rfc822MessageID column (Alternate Message ID for searching - you can find from get_messages or get_message endpoint output
-- Search='to:david' --search example for => to (name)
-- Search='to:david.smith@gmail.com' --search example for => to (email)
-- Search='from:david' --search example for => from (name)
-- Search='from:david.smith@gmail.com' --search example for => from (email)
-- Search='from:(Platform Notifications) OR from:(no-reply@accounts.google.com) ' --search example for => from (name or email)
-- Search='cc:david' --search example for => cc (name)
-- Search='bcc:david' --search example for => bcc (name)
-- Search='is:unread AND subject:(Share request for)' --search example for => multiple conditions (AND)
-- Search='is:unread OR subject:(Share request for)' --search example for => multiple conditions (OR)
-- Search='from:someuser@example.com' --search example for => from sender=from:someuser@example.com
-- Search='from:a@company.com OR from:b@company.com' --search example for => from sender (OR)
-- Search='from:amy' --search example for => from sender by name=from:amy
-- Search='from:amy OR from:bob ' --search example for => from sender by name (OR)
-- Search='has:attachment' --search example for => has attachment=has:attachment
-- Search='larger:10M' --search example for => has attachment (larger than 10MB)
-- Search='smaller:10M' --search example for => has attachment (smaller than 10MB)
-- Search='smaller:10M' --search example for => has attachment (smaller than 10MB)
-- Search='1024' --search example for => size (exact bytes)
-- Search='unread=is:unread' --search example for => is unread=is:unread
-- Search='is:read' --search example for => is read=is:read
-- Search='after:2004/04/16' --search example for => date after=after:2004/04/16
-- Search='before:2004/04/16' --search example for => date before=before:2004/04/16
-- Search='older_than:2d' --search example for => age older than (2days)
-- Search='older_than:4y' --search example for => age older than (4years)
-- Search='newer_than:2d' --search example for => age newer than (2days)
-- Search='newer_than:4m' --search example for => age newer than (4months)
-- Search='from:someuser@example.com rfc822msgid:<008601dae391zzzzzzz> is:unread' --search example for => from specific sender with specific message id(RFC822) and unread emails only=from:someuser@example.com rfc822msgid:<somemsgid@example.com> is:unread
-- Search='in:sent after:2014/01/01 before:2014/02/01' --search example for => sent date range (static dates)
-- Search='in:sent after:<<yearstart-1day+22hour|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1day|~|yyyy/MM/dd,FUN_TO_DATE>>' --search example for => sent date range (dynamic dates). You can use keywords like now,today,yesterday,monthstart,monthend,yearstart,yearend,weekstart,weekend along with operator + / - [hour,minute,second,day,month,year]
)
Microsoft SQL Server OPENQUERY Query - Gmail Example
Following examples shows how to Get all messages with search condition(s) in Microsoft SQL Server using OPENQUERY Query. This command facilitates the execution of pass-through queries on remote servers. Below example is demonstrating the usage of OPENQUERY.
SELECT * FROM OPENQUERY([LS_TO_GMAIL_IN_GATEWAY],
'SELECT *
FROM Messages
--Use WITH clause --OR-- Key column(s) in WHERE clause. If you use Id in Where clause then Search parameter is ignored
--WHERE [Id] = ''18fb7747b0136726''
WITH(
Search=''after:<<yearstart+1d|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1d|~|yyyy/MM/dd,FUN_TO_DATE>>'' --search for mail sent between some dates (after year start plus one day and before yesterday (i.e. today-1d))
-- Search=''after:2024/01/31 before:2024/05/25'' --use of static date
--for more examples refer https://support.google.com/mail/answer/7190
-- Search=''FREE PRODUCT'' --search example for=> has words anywhere in the subject or body
-- Search=''"FREE PRODUCT"'' --search example for=> has exact phrase anywhere in the subject or body
-- Search=''subject:FREE PRODUCT'' --search example for=> has subject (contains any word)
-- Search=''subject:(FREE PRODUCT)'' --search example for => has subject (contains exact phrase)
-- Search=''Rfc822msgid:<008601dae391$fda78bf0$f8f6a3d0$@zappysys.com>'' --search example for => Search by Rfc822MessageID column (Alternate Message ID for searching - you can find from get_messages or get_message endpoint output
-- Search=''to:david'' --search example for => to (name)
-- Search=''to:david.smith@gmail.com'' --search example for => to (email)
-- Search=''from:david'' --search example for => from (name)
-- Search=''from:david.smith@gmail.com'' --search example for => from (email)
-- Search=''from:(Platform Notifications) OR from:(no-reply@accounts.google.com) '' --search example for => from (name or email)
-- Search=''cc:david'' --search example for => cc (name)
-- Search=''bcc:david'' --search example for => bcc (name)
-- Search=''is:unread AND subject:(Share request for)'' --search example for => multiple conditions (AND)
-- Search=''is:unread OR subject:(Share request for)'' --search example for => multiple conditions (OR)
-- Search=''from:someuser@example.com'' --search example for => from sender=from:someuser@example.com
-- Search=''from:a@company.com OR from:b@company.com'' --search example for => from sender (OR)
-- Search=''from:amy'' --search example for => from sender by name=from:amy
-- Search=''from:amy OR from:bob '' --search example for => from sender by name (OR)
-- Search=''has:attachment'' --search example for => has attachment=has:attachment
-- Search=''larger:10M'' --search example for => has attachment (larger than 10MB)
-- Search=''smaller:10M'' --search example for => has attachment (smaller than 10MB)
-- Search=''smaller:10M'' --search example for => has attachment (smaller than 10MB)
-- Search=''1024'' --search example for => size (exact bytes)
-- Search=''unread=is:unread'' --search example for => is unread=is:unread
-- Search=''is:read'' --search example for => is read=is:read
-- Search=''after:2004/04/16'' --search example for => date after=after:2004/04/16
-- Search=''before:2004/04/16'' --search example for => date before=before:2004/04/16
-- Search=''older_than:2d'' --search example for => age older than (2days)
-- Search=''older_than:4y'' --search example for => age older than (4years)
-- Search=''newer_than:2d'' --search example for => age newer than (2days)
-- Search=''newer_than:4m'' --search example for => age newer than (4months)
-- Search=''from:someuser@example.com rfc822msgid:<008601dae391zzzzzzz> is:unread'' --search example for => from specific sender with specific message id(RFC822) and unread emails only=from:someuser@example.com rfc822msgid:<somemsgid@example.com> is:unread
-- Search=''in:sent after:2014/01/01 before:2014/02/01'' --search example for => sent date range (static dates)
-- Search=''in:sent after:<<yearstart-1day+22hour|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1day|~|yyyy/MM/dd,FUN_TO_DATE>>'' --search example for => sent date range (dynamic dates). You can use keywords like now,today,yesterday,monthstart,monthend,yearstart,yearend,weekstart,weekend along with operator + / - [hour,minute,second,day,month,year]
)')
Microsoft SQL Server EXEC Query - Gmail Example (Handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements, which often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, there is a solution. Starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_GMAIL_IN_GATEWAY] syntax. Following examples shows how to Get all messages with search condition(s) in Microsoft SQL Server using EXEC Query.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT *
FROM Messages
--Use WITH clause --OR-- Key column(s) in WHERE clause. If you use Id in Where clause then Search parameter is ignored
--WHERE [Id] = ''18fb7747b0136726''
WITH(
Search=''after:<<yearstart+1d|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1d|~|yyyy/MM/dd,FUN_TO_DATE>>'' --search for mail sent between some dates (after year start plus one day and before yesterday (i.e. today-1d))
-- Search=''after:2024/01/31 before:2024/05/25'' --use of static date
--for more examples refer https://support.google.com/mail/answer/7190
-- Search=''FREE PRODUCT'' --search example for=> has words anywhere in the subject or body
-- Search=''"FREE PRODUCT"'' --search example for=> has exact phrase anywhere in the subject or body
-- Search=''subject:FREE PRODUCT'' --search example for=> has subject (contains any word)
-- Search=''subject:(FREE PRODUCT)'' --search example for => has subject (contains exact phrase)
-- Search=''Rfc822msgid:<008601dae391$fda78bf0$f8f6a3d0$@zappysys.com>'' --search example for => Search by Rfc822MessageID column (Alternate Message ID for searching - you can find from get_messages or get_message endpoint output
-- Search=''to:david'' --search example for => to (name)
-- Search=''to:david.smith@gmail.com'' --search example for => to (email)
-- Search=''from:david'' --search example for => from (name)
-- Search=''from:david.smith@gmail.com'' --search example for => from (email)
-- Search=''from:(Platform Notifications) OR from:(no-reply@accounts.google.com) '' --search example for => from (name or email)
-- Search=''cc:david'' --search example for => cc (name)
-- Search=''bcc:david'' --search example for => bcc (name)
-- Search=''is:unread AND subject:(Share request for)'' --search example for => multiple conditions (AND)
-- Search=''is:unread OR subject:(Share request for)'' --search example for => multiple conditions (OR)
-- Search=''from:someuser@example.com'' --search example for => from sender=from:someuser@example.com
-- Search=''from:a@company.com OR from:b@company.com'' --search example for => from sender (OR)
-- Search=''from:amy'' --search example for => from sender by name=from:amy
-- Search=''from:amy OR from:bob '' --search example for => from sender by name (OR)
-- Search=''has:attachment'' --search example for => has attachment=has:attachment
-- Search=''larger:10M'' --search example for => has attachment (larger than 10MB)
-- Search=''smaller:10M'' --search example for => has attachment (smaller than 10MB)
-- Search=''smaller:10M'' --search example for => has attachment (smaller than 10MB)
-- Search=''1024'' --search example for => size (exact bytes)
-- Search=''unread=is:unread'' --search example for => is unread=is:unread
-- Search=''is:read'' --search example for => is read=is:read
-- Search=''after:2004/04/16'' --search example for => date after=after:2004/04/16
-- Search=''before:2004/04/16'' --search example for => date before=before:2004/04/16
-- Search=''older_than:2d'' --search example for => age older than (2days)
-- Search=''older_than:4y'' --search example for => age older than (4years)
-- Search=''newer_than:2d'' --search example for => age newer than (2days)
-- Search=''newer_than:4m'' --search example for => age newer than (4months)
-- Search=''from:someuser@example.com rfc822msgid:<008601dae391zzzzzzz> is:unread'' --search example for => from specific sender with specific message id(RFC822) and unread emails only=from:someuser@example.com rfc822msgid:<somemsgid@example.com> is:unread
-- Search=''in:sent after:2014/01/01 before:2014/02/01'' --search example for => sent date range (static dates)
-- Search=''in:sent after:<<yearstart-1day+22hour|~|yyyy/MM/dd,FUN_TO_DATE>> before:<<today-1day|~|yyyy/MM/dd,FUN_TO_DATE>>'' --search example for => sent date range (dynamic dates). You can use keywords like now,today,yesterday,monthstart,monthend,yearstart,yearend,weekstart,weekend along with operator + / - [hour,minute,second,day,month,year]
)'
EXEC (@MyQuery) AT [LS_TO_GMAIL_IN_GATEWAY]
Getting Started with Examples
ZappySys API Driver is a powerful software solution designed to facilitate the extraction and integration of data from a wide range of sources through APIs. Its intuitive design and extensive feature set make it an essential asset for any organization dealing with complex data integration tasks.
To get started with examples using ZappySys API Driver, please click on the following applications:
Key features of the ZappySys API Driver include:
The API ODBC driver facilitates the reading and writing of data from numerous popular online services (refer to the complete list here) using familiar SQL language without learning complexity of REST API calls. The driver allows querying nested structure and output as a flat table. You can also create your own ODBC / Data Gateway API connector file and use it with this driver.
Intuitive Configuration: The interface is designed to be user-friendly, enabling users to easily set up the specific API endpoints within Gmail without requiring extensive technical expertise or programming knowledge.
Customizable Endpoint Setup: Users can conveniently configure the API endpoint settings, including the HTTP request method, endpoint URL, and any necessary parameters, to precisely target the desired data within Gmail.
Data Manipulation Capabilities: The ZappySys API Driver allows for seamless data retrieval and writing, enabling users to fetch data from Gmail and perform various data manipulation operations as needed, all through an intuitive and straightforward interface.
Secure Authentication Integration: The driver provides secure authentication integration, allowing users to securely connect to the Gmail API by inputting the necessary authentication credentials, such as API tokens or other authentication keys.
Error Handling Support: The interface is equipped with comprehensive error handling support, ensuring that any errors or exceptions encountered during the data retrieval or writing process are efficiently managed and appropriately communicated to users for prompt resolution.
Data Visualization and Reporting: The ZappySys API Driver facilitates the seamless processing and presentation of the retrieved data from Gmail, enabling users to generate comprehensive reports and visualizations for further analysis and decision-making purposes.
Overall, the ZappySys API Driver serves as a powerful tool for streamlining the integration of applications with Gmail, providing users with a convenient and efficient way to access and manage data, all through a user-friendly and intuitive interface.