views:

2704

answers:

4

I need to connect to an Exchange mailbox in a Python script, without using any profile setup on the local machine (including using Outlook). If I use win32com to create a MAPI.Session I could logon (with the Logon() method) with an existing profile, but I want to just provide a username & password.

Is this possible? If so, could someone provide example code? I would prefer if it only used the standard library and the pywin32 package. Unfortunately, enabling IMAP access for the Exchange server (and then using imaplib) is not possible.

In case it is necessary: all the script will be doing is connecting to the mailbox, and running through the messages in the Inbox, retrieving the contents. I can handle writing the code for that, if I can get a connection in the first place!

To clarify regarding Outlook: Outlook will be installed on the local machine, but it does not have any accounts setup (i.e. all the appropriate libraries will be available, but I need to operate independently from anything setup inside of Outlook).

+2  A: 

I'm pretty sure this is going to be impossible without using Outlook and a MAPI profile. If you can sweet talk your mail admin into enabling IMAP on the Exchange server it would make your life a lot easier.

Harley
Enabling IMAP is not an option (the whole thing would be trivial if it was, but sadly it is not).
Tony Meyer
Yeah that's what I figured but it was worth a shot.
Harley
I should probably have put that in the question in the first place (made that edit now). Thanks :)
Tony Meyer
There is a possiblility you can do what you want with Exchange 2007 using powershell, but I don't know much about it.
Harley
+1  A: 

You'll have to find a way to run the process as that particular user.

See this.

I think pywin32.CreateProcessAsUser is the start of the path you need to go down. One last edit. The logged on user handle is obtained from using the win32security.LogonUser method

Sam Corder
+1  A: 

i am looking for something similar - check out http://code.google.com/p/weboutlook/

Bharani
+1  A: 

I know this is an old thread, but...

If you're using Exchange 2007 or 2010, take a look at Exchange Web Services. It's a pretty comprehensive SOAP-based interface for Exchange, and you can do pretty much anything Outlook is able to do, including delegate access to other user accounts.

http://msdn.microsoft.com/en-us/library/bb204119.aspx

Erik Cederstrand