Endpoint Get List of Messages for a Specific User
Name
get_messages
Description
Lists the messages for the specified user
Related Tables
Parameters
| Parameter | Required | Options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Name:
Label: ApiVersion The version of the API to use. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: UserId Enter the Gmail user ID. |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: Search Expression Expression to return messages matching the specified query. Supports the same query format as the Gmail search box. |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: IncludeSpamTrash Include messages from SPAM and TRASH in the results. |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: LabelIds Only return messages with labels that match all of the specified label IDs. Messages in a thread might have labels that other messages in the same thread don't have. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: MaxResults Maximum number of messages to return. This field defaults to 100. The maximum allowed value for this field is 500. |
Output Columns
| Label | Data Type (SSIS) | Data Type (SQL) | Length | Description |
|---|---|---|---|---|
| Id |
DT_WSTR
|
nvarchar(500)
|
500 | |
| Subject |
DT_WSTR
|
nvarchar(300)
|
300 | |
| BodySnippet |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
| To |
DT_WSTR
|
nvarchar(200)
|
200 | |
| ToEmail |
DT_WSTR
|
nvarchar(200)
|
200 | |
| Date |
DT_WSTR
|
nvarchar(200)
|
200 | |
| From |
DT_WSTR
|
nvarchar(200)
|
200 | |
| FromEmail |
DT_WSTR
|
nvarchar(200)
|
200 | |
| PlainTextBody |
DT_NTEXT
|
nvarchar(MAX)
|
||
| HtmlBody |
DT_NTEXT
|
nvarchar(MAX)
|
||
| ContentType |
DT_WSTR
|
nvarchar(200)
|
200 | |
| LabelIds |
DT_WSTR
|
nvarchar(500)
|
500 | |
| ThreadId |
DT_WSTR
|
nvarchar(500)
|
500 | |
| PayloadMimeType |
DT_WSTR
|
nvarchar(200)
|
200 | |
| PayloadBodySize |
DT_I4
|
int
|
||
| SizeEstimate |
DT_I4
|
int
|
||
| HistoryId |
DT_WSTR
|
nvarchar(500)
|
500 | |
| InternalDate |
DT_WSTR
|
nvarchar(200)
|
200 | |
| MessageDate |
DT_DBTIMESTAMP
|
datetime
|
||
| GoogleSmtpSource |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
| ReturnPath |
DT_WSTR
|
nvarchar(500)
|
500 | |
| ReceivedSPF |
DT_WSTR
|
nvarchar(500)
|
500 | |
| Rfc822MessageID |
DT_WSTR
|
nvarchar(200)
|
200 | |
| MIMEVersion |
DT_WSTR
|
nvarchar(20)
|
20 | |
| Mailer |
DT_WSTR
|
nvarchar(200)
|
200 | |
| ThreadIndex |
DT_WSTR
|
nvarchar(500)
|
500 | |
| ContentLanguage |
DT_WSTR
|
nvarchar(100)
|
100 |
Input Columns
| Label | Data Type (SSIS) | Data Type (SQL) | Length | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| There are no Static columns defined for this endpoint. This endpoint detects columns dynamically at runtime. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Examples
SSIS
Use Gmail Connector in API Source or in API Destination SSIS Data Flow components to read or write data.
API Source
This Endpoint belongs to the Messages table, therefore it is better to use it, instead of accessing the endpoint directly:
| There are no parameters to configure. |
API Destination
This Endpoint belongs to the Messages table, therefore it is better to use it, instead of accessing the endpoint directly. Use this table and table-operation pair to get list of messages for a specific user:
| There are no parameters to configure. |
ODBC application
Use these SQL queries in your ODBC application data source:
Get all messages
SELECT * FROM Messages
Get all messages for a specified user
Get all messages for a specified user id (mailbox). Thi is very slow row by row operation. For each message one API call is invoked so do not try this way unless you have to.
SELECT * FROM Messages
LIMIT 10 --This will only fetch first 10 messages from the result (Fetching all messages can be very slow (Rowbecuase its Row-By-Row operation)
WITH (UserID='me')
--WITH (UserID='firstname.lastname@domainname.com')
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
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]
)
get_messages endpoint belongs to
Messages
table(s), and can therefore be used via those table(s).
SQL Server
Use these SQL queries in SQL Server after you create a data source in Data Gateway:
Get all messages
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Messages';
EXEC (@MyQuery) AT [LS_TO_GMAIL_IN_GATEWAY];
Get all messages for a specified user
Get all messages for a specified user id (mailbox). Thi is very slow row by row operation. For each message one API call is invoked so do not try this way unless you have to.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Messages
LIMIT 10 --This will only fetch first 10 messages from the result (Fetching all messages can be very slow (Rowbecuase its Row-By-Row operation)
WITH (UserID=''me'')
--WITH (UserID=''firstname.lastname@domainname.com'')';
EXEC (@MyQuery) AT [LS_TO_GMAIL_IN_GATEWAY];
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
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];
get_messages endpoint belongs to
Messages
table(s), and can therefore be used via those table(s).