By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,403 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,403 IT Pros & Developers. It's quick & easy.

Python and MS Exchange

P: n/a
I'm using python 2.3 and Windows 2000 "Professional" to access a Microsoft
Exchange Server to monitor messages and perform various tasks around the
office. My little program is attracted quite a bit of attention and I have
been asked to add some features, but I don't know how to do a couple of
things. Can anyone either help me out with the details, or point me to
where I can get the information? Here's my task list:

1. Create a folder for the mailbox. For example, I would like to have a
"Processed" folder where I can move messages once they have been processed.

2. How can I check to see if a folder exists?

3. Can I access the allotted size of a folder to determine if I have room
to post messages?

4. How do I move a message to the folder I just created?

Thanks for any help you can pass my way.
--greg

Greg Lindstrom, IBCATS Development
Acxiom Corporation
(501) 342-1626 Gr***********@acxiom.com

We who cut mere stones must always be envisioning cathedrals. -- Quarry
Worker's Creed

************************************************** ********************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Lindstrom Greg - glinds wrote:
I'm using python 2.3 and Windows 2000 "Professional" to access a Microsoft
Exchange Server to monitor messages and perform various tasks around the
office. My little program is attracted quite a bit of attention and I have
been asked to add some features, but I don't know how to do a couple of
things. Can anyone either help me out with the details, or point me to
where I can get the information? Here's my task list:

1. Create a folder for the mailbox. For example, I would like to have a
"Processed" folder where I can move messages once they have been processed.

2. How can I check to see if a folder exists?

3. Can I access the allotted size of a folder to determine if I have room
to post messages?

4. How do I move a message to the folder I just created?

Can you tell us what object model you are using? Provide a little
sample code to give us a clue.

1) If you are yusing MAPI, there is a CreateFolder method.
2) Try to open it, and if it fails, check the error code.
3) This is probably in a property on the folder. Check the Exchange
forums for what folder property you need.
4) A "Move" method.

Check out the SpamBayes project, and look at the source code to the
Outlook Addin - in general, this uses MAPI (which is basically the
'exchange object model'), but also does a few things via the Outlook
object model - so you get a few examples of both. MAPI has a bigger
learning curve, but is more powerful and faster.

Mark

Jul 18 '05 #2

P: n/a
Mark Hammond <mh******@skippinet.com.au> wrote in message news:<c0**********@arachne.labyrinth.net.au>...

Check out the SpamBayes project, and look at the source code to the
Outlook Addin - in general, this uses MAPI (which is basically the
'exchange object model'), but also does a few things via the Outlook
object model - so you get a few examples of both. MAPI has a bigger
learning curve, but is more powerful and faster.


And Outlook Explorer might also be useful as a starting point:

http://www.boddie.org.uk/python/COM.html

There's just archiving going on in that program, but it could be more
productive to look at its source code than it is to swim in the MSDN
documentation.

Paul
Jul 18 '05 #3

P: n/a
> Can you tell us what object model you are using? Provide a little
sample code to give us a clue.
Sure thing.

from win32all.client import Dispatch

mailbox = Dispatch("MAPI.session")
mailbox.Login(profile='MS Exchange Settings')

# Now *I* think I should be able to do the following
mailbox.listfolders()

# but I get...
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\site-packages\win32com\client\dynamic.py",
line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: MAPI.Session.listfolders

# so, I've already taken a wrong turn!
I've got the SpamBayes source code (BTW- I've been using SpamBayes for
about 6 months and love it...very little SPAM gets through to me
anymore) and will be looking it over this weekend.

Is there a way to examine the mailbox object above to see what methods
are available?

Thanks for your help. I am keeping notes and plan to write up a
summary for others.

--greg


1) If you are yusing MAPI, there is a CreateFolder method.
2) Try to open it, and if it fails, check the error code.
3) This is probably in a property on the folder. Check the Exchange
forums for what folder property you need.
4) A "Move" method.

Check out the SpamBayes project, and look at the source code to the
Outlook Addin - in general, this uses MAPI (which is basically the
'exchange object model'), but also does a few things via the Outlook
object model - so you get a few examples of both. MAPI has a bigger
learning curve, but is more powerful and faster.

Mark

Jul 18 '05 #4

P: n/a
Greg Lindstrom wrote:
Can you tell us what object model you are using? Provide a little
sample code to give us a clue.

Sure thing.

from win32all.client import Dispatch

mailbox = Dispatch("MAPI.session")
mailbox.Login(profile='MS Exchange Settings')


OK - you are using 'simple MAPI', and this is going to be a problem for
you down the track. The biggest one will be the security dialog new
versions Outlook use.

This *is* an OK way to start, but don't go too far down this track - it
is a dead end. On the positive side, it is possible to combine this
'simple MAPI' with 'extended MAPI' (the latter is what SpamBayes uses)

Simple MAPI is also known as "CDO"
mailbox = Dispatch("MAPI.session")


Note that what you have here is a 'session' object. Looking in the MSDN
documentation for the CDO session object, there is no 'listfolders' method.

What you probably want is something like:
session = Dispatch("MAPI.session")
session.Logon(...)
inbox = session.Inbox
print "Inbox name is", inbox.Name
for i in range(inbox.Messages.Count):
message = inbox.Messages.Item(i+1)
# now 'message' has properties like 'Subject' etc

See the CDO documentation for more details.

Mark.

Jul 18 '05 #5

P: n/a
Mark (and others),

Thanks for your time and attention. Since I expect to eventually want
to do all sorts of things with this application, I think it's best to
use MAPI (and not simple MAPI). I have the SpamBayes MAPIDriver (and
everything else out of the "sandbox") and have stepped through it
enough to figure most of it out. When I run "dump_profiles.py", I get
the "MS Exchange Settings" (as I expected). When I run the
"dump_props.py" it complains that "FalseGetAllItems" is not defined.
Humph. When I attempt the "extract_prop.py -p Subject test" it
complains about not being able to find a default message store.

I have read through a lot of the MSDN Docum
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.