querying outlook

CJ_London

Super Moderator
Staff member
Local time
Today, 19:18
Joined
Feb 19, 2013
Messages
17,301
I know how to query outlook using sql to return emails in an outlook folder. One of the fields returned is a boolean to indicate whether the email has attachments. I also know how to get the attachment names (and the files if required) via the outlook object, but wondered if there is a sql way of returning the attachment names.

Using office 2010, the sql to return the emails in a specified folder (a subfolder of the inbox in this case) is

Code:
SELECT *
FROM [Outlook 9.0;MAPILEVEL=myemailaddress|\inbox\PROFILE=Outlook;TABLETYPE=0;TABLENAME=For Processing;COLSETVERSION=12.0;DATABASE=C:\Users\{username}\AppData\Local\Temp\].[subfolder] AS O

research indicates attachments are in a table

so in theory it should just be a matter of getting the connection string correct. Perhaps need to include some sort of ID for a specific email? a different tabletype or name?

this link refers to properties which is effectively what I use at the moment via the outlook object

but nothing in SQL?
 
I can set a link to Outlook Inbox folder and see the connection string.
I used that in query with [Inbox] as [subfolder] and query works.

Your reference doc doesn't show Attachment is used by MAPI, so guessing that won't work in connection string. Maybe this is not possible with SQL.

As I understand them, Outlook tables are not really tables, not as we know tables in Access. Seems Attachment "table" is a property of email object, kind of like a multi-value field in Access table which requires special handling in Access to read content. So my guess is Outlook Attachment table cannot be directly read in SQL. If there is a connection string to allow, I am not finding.
 
Last edited:
It probably isn’t possible but thought it was worth floating the question. The sql would still need to be created in vba

The reason for wanting to use sql is (for emails in a folder at any rate) significantly faster than the outlook object method
 

Users who are viewing this thread

Back
Top Bottom