Reading Outlook/Exchange Email Programatically with Python
Reading Outlook/Exchange Email Programatically with Python
Submitted by Corey Goldberg on Wed, 28/02/2007 - 18:36.With Python's Windows Extensions, you can talk via COM to an Exchange Server and read/process your email. You must have the Outlook Client installed on the box you are running this from.
Here is a sample script that will:
- connect to your mailbox
- print the inbox name
- print the message count
- print the subjects for all your email messages
#!/usr/bin/env python
from win32com.client import Dispatch
session = Dispatch("MAPI.session")
session.Logon('OUTLOOK') # MAPI profile name
inbox = session.Inbox
print "Inbox name is:", inbox.Name
print "Number of messages:", inbox.Messages.Count
for i in range(inbox.Messages.Count):
message = inbox.Messages.Item(i + 1)
print message.Subject
from win32com.client import Dispatch
session = Dispatch("MAPI.session")
session.Logon('OUTLOOK') # MAPI profile name
inbox = session.Inbox
print "Inbox name is:", inbox.Name
print "Number of messages:", inbox.Messages.Count
for i in range(inbox.Messages.Count):
message = inbox.Messages.Item(i + 1)
print message.Subject
