Reading mails from Outlook
beeswax
sam.schelfhout at gmail.com
Fri Feb 23 06:31:17 EST 2007
On 22 feb, 15:45, Larry Bates <lba... at websafe.com> wrote:
> beeswax wrote:
> > Hi,
>
> > Does anyone knows how to read e-mails from a specific folders in
> > outlook?
> > I only found out how to read the mails from the inbox folder and how
> > to list all available folder.
> > I just don't found a way to access my mails from the other folders.
>
> > Can anyone help me?
>
> > Regards,
>
> > Sam
>
> I'll bet that some of the best information you can get about interacting
> with Outlook is going to be by looking at the sourcecode to SpamBayes
> plug-in. You can get it from here:
>
> https://sourceforge.net/project/showfiles.php?group_id=61702&package_...
>
> -Larry
Hi again,
I found the solution myself, the next code will iterate all folders,
sub folders and their mails.
I just needed to understand what I could do with the folders objects.
But, this code will trow an error when trying to connect to shared
folders (exchange folders etc).
Btw does anyone knows a good API for this, or a way to get all the
properties from an object?
# Create instance of Outlook
o = win32com.client.gencache.EnsureDispatch("Outlook.Application")
# Dump all folders recursive, starting from root
DumpFoldersRecursive(o.GetNamespace("MAPI").Folders,0)
o = None
def DumpFoldersRecursive(folders,indent):
# Note: the com indexes start from 1
for i in range(1,folders.Count+1):
folder = folders[i]
print '%sFolder %d: "%s"' %
('\t'*indent,i,DecodeUnicodeString(folder.Name))
# if a folder has no subfolders, its Folders.Count will be
zero, so this is safe.
for i in range(len(folder.Items)):
message = folder.Items[i+1]
print message.Subject
DumpFoldersRecursive(folder.Folders,indent+1)
Regards,
Sam
More information about the Python-list
mailing list