Endpoint Download Messages by Search Condition (Multiple *.EML Files RFC 822 / MIME)
Name
download_messages_by_search
Description
Downloads multiple messages as *.EML File type (RFC 822 / MIME) for a specified search condition / mailbox / folder
Parameters
Parameter | Required | Options | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Name:
Label: User ID or Email The Microsoft Mail user ID GUID or email address for the account to read messages from. (Examples: '4ff54a77-9c09-4274-958f-83bdc0a53900' or 'first.last@domain.com') |
YES | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: SaveFolder Specify a disk folder path to save file(s) to |
YES | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: Email Body Format |
YES |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: MailFolderId |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: OverwriteFile |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: Search Criteria Data filter (e.g. somecolumn -eq 'somevalue'), you can use Date time functions for dynamic date. You can use keywords like now,today,yesterday,monthstart,monthend,yearstart,yearend,weekstart,weekend along with operator + / - [hour,minute,second,day,month,year] |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: Order By Order the specified column by ascending or descending order |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: Page Size The number of records to include in each page of results |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Name:
Label: Selected Columns Select the individual columns to be included in the response, to reduce the response size and increase performance |
Output Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Description |
---|---|---|---|---|
MessageId |
DT_STR
|
varchar(255)
|
255 | |
SavedFileSize |
DT_I8
|
bigint
|
||
StatusCode |
DT_I4
|
int
|
||
ErrorMessage |
DT_STR
|
varchar(4000)
|
4000 | |
UserId |
DT_STR
|
varchar(255)
|
255 | |
MailFolderId |
DT_STR
|
varchar(255)
|
255 | |
ODataETag |
DT_WSTR
|
nvarchar(1000)
|
1000 | |
Categories |
DT_WSTR
|
nvarchar(1000)
|
1000 | |
ParentFolderId |
DT_WSTR
|
nvarchar(1200)
|
1200 | |
ConversationId |
DT_WSTR
|
nvarchar(1200)
|
1200 | |
ConversationIndex |
DT_WSTR
|
nvarchar(1200)
|
1200 | |
IsDeliveryReceiptRequested |
DT_BOOL
|
bit
|
||
IsReadReceiptRequested |
DT_BOOL
|
bit
|
||
IsRead |
DT_BOOL
|
bit
|
||
IsDraft |
DT_BOOL
|
bit
|
||
WebLink |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
InferenceClassification |
DT_WSTR
|
nvarchar(800)
|
800 | |
InternetMessageHeaders |
DT_NTEXT
|
nvarchar(MAX)
|
||
BodyContentType |
DT_WSTR
|
nvarchar(500)
|
500 | |
BccRecipient5 |
DT_WSTR
|
nvarchar(200)
|
200 | |
FromEmailAddressName |
DT_WSTR
|
nvarchar(800)
|
800 | |
FromEmailAddress |
DT_WSTR
|
nvarchar(800)
|
800 | |
ReplyTo |
DT_WSTR
|
nvarchar(1190)
|
1190 | |
UniqueBodyContentType |
DT_WSTR
|
nvarchar(500)
|
500 | |
UniqueBodyContent |
DT_NTEXT
|
nvarchar(MAX)
|
||
FlagFlagStatus |
DT_WSTR
|
nvarchar(800)
|
800 | |
InternetMessageId |
DT_WSTR
|
nvarchar(1800)
|
1800 | |
BodyContent |
DT_NTEXT
|
nvarchar(MAX)
|
||
BccRecipient4 |
DT_WSTR
|
nvarchar(200)
|
200 | |
BccRecipient2 |
DT_WSTR
|
nvarchar(200)
|
200 | |
HasAttachments |
DT_BOOL
|
bit
|
||
Subject |
DT_WSTR
|
nvarchar(800)
|
800 | |
BodyPreview |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
SenderEmailAddressName |
DT_WSTR
|
nvarchar(800)
|
800 | |
SenderEmailAddress |
DT_WSTR
|
nvarchar(800)
|
800 | |
Importance |
DT_WSTR
|
nvarchar(500)
|
500 | |
SentDateTime |
DT_DBTIMESTAMP
|
datetime
|
||
CreatedDateTime |
DT_DBTIMESTAMP
|
datetime
|
||
LastModifiedDateTime |
DT_DBTIMESTAMP
|
datetime
|
||
ChangeKey |
DT_WSTR
|
nvarchar(1000)
|
1000 | |
ToRecipients |
DT_WSTR
|
nvarchar(1190)
|
1190 | |
BccRecipient3 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipients |
DT_WSTR
|
nvarchar(1190)
|
1190 | |
ToRecipient1 |
DT_WSTR
|
nvarchar(200)
|
200 | |
ToRecipient2 |
DT_WSTR
|
nvarchar(200)
|
200 | |
ToRecipient3 |
DT_WSTR
|
nvarchar(200)
|
200 | |
ToRecipient4 |
DT_WSTR
|
nvarchar(200)
|
200 | |
ToRecipient5 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipient1 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipient2 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipient3 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipient4 |
DT_WSTR
|
nvarchar(200)
|
200 | |
CcRecipient5 |
DT_WSTR
|
nvarchar(200)
|
200 | |
BccRecipient1 |
DT_WSTR
|
nvarchar(200)
|
200 | |
BccRecipients |
DT_WSTR
|
nvarchar(1190)
|
1190 | |
ReceivedDateTime |
DT_DBTIMESTAMP
|
datetime
|
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 Outlook Mail (Office 365) Connector in API Source or in API Destination SSIS Data Flow components to read or write data.
API Source
Required Parameters | |
---|---|
User ID or Email | Fill-in the parameter... |
SaveFolder | Fill-in the parameter... |
Optional Parameters | |
MailFolderId | |
OverwriteFile | True |

API Destination
Required Parameters | |
---|---|
User ID or Email | Fill-in the parameter... |
SaveFolder | Fill-in the parameter... |
Optional Parameters | |
MailFolderId | |
OverwriteFile | True |

ODBC application
Use these SQL queries in your ODBC application data source:
Download Multiple Outlook Emails as .EML Files (RFC 822 / MIME) with Search Filters
This example shows how to search for outlook messages and download Office 365 Email messages as EML file (RFC 822 / MIME) using search conditions and by User Id, MailFolder Id. It will save each message as its own local file. This file type can be opened by most email clients, *.eml file saves along with attachments.
SELECT * FROM download_messages_by_search
WITH(
SaveFolder='c:\download', --save as *.eml files
OverwriteFile='True',
MailFolderId='INBOX', --or use mailbox folder Id (see get_mailfolders endpoint)
UserId='me', --or use "user-id" or use "email"
--search mail with attachments, sent after 2023-03-01, subject contains string "invoice" and from email is microsoft-noreply@microsoft.com
--SearchCriteria='hasAttachments eq true and sentDateTime gt 2023-03-01 and contains(subject, ''invoice'') and from/emailAddress/address eq ''microsoft-noreply@microsoft.com'' ',
)
--Check this link to learn more about search conditions: https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http
SQL Server
Use these SQL queries in SQL Server after you create a data source in Data Gateway:
Download Multiple Outlook Emails as .EML Files (RFC 822 / MIME) with Search Filters
This example shows how to search for outlook messages and download Office 365 Email messages as EML file (RFC 822 / MIME) using search conditions and by User Id, MailFolder Id. It will save each message as its own local file. This file type can be opened by most email clients, *.eml file saves along with attachments.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM download_messages_by_search
WITH(
SaveFolder=''c:\download'', --save as *.eml files
OverwriteFile=''True'',
MailFolderId=''INBOX'', --or use mailbox folder Id (see get_mailfolders endpoint)
UserId=''me'', --or use "user-id" or use "email"
--search mail with attachments, sent after 2023-03-01, subject contains string "invoice" and from email is microsoft-noreply@microsoft.com
--SearchCriteria=''hasAttachments eq true and sentDateTime gt 2023-03-01 and contains(subject, ''''invoice'''') and from/emailAddress/address eq ''''microsoft-noreply@microsoft.com'''' '',
)
--Check this link to learn more about search conditions: https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http';
EXEC (@MyQuery) AT [LS_TO_OUTLOOK_MAIL_OFFICE_365_IN_GATEWAY];