473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Python and MS Exchange

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
5 4684
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
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: warren ali | last post by:
Hi all! I'm new to python and I seem to have a hit a of a brick wall. I hope you guys can help. I'm trying to rewrite some of my vbscripts in python. This particular script connects to a...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
3
by: Yusniel | last post by:
Hi friends. Someone know how to work with python and exchange server?.
1
by: Jean-Paul Calderone | last post by:
On Mon, 5 May 2008 11:11:19 -0700 (PDT), TkNeo <tarun.kap@gmail.comwrote: FWIW, though not as complete as an OpenSSL wrapper as M2Crypto, pyOpenSSL works with Python 2.3. As far as the details...
3
by: Beliavsky | last post by:
I work for a financial company where we run Windows XP and read email using Microsoft Outlook 2003. I get daily files that come as email attachments from various counterparties. I save them as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.