473,587 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python and MS Exchange

I'm using python 2.3 and Windows 2000 "Profession al" 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***********@a cxiom.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 4723
Lindstrom Greg - glinds wrote:
I'm using python 2.3 and Windows 2000 "Profession al" 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******@skipp inet.com.au> wrote in message news:<c0******* ***@arachne.lab yrinth.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(p rofile='MS Exchange Settings')

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

# but I get...
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
File "C:\Python23\li b\site-packages\win32c om\client\dynam ic.py",
line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: MAPI.Session.li stfolders

# 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(p rofile='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.Mes sages.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 "FalseGetAllIte ms" is not defined.
Humph. When I attempt the "extract_prop.p y -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
1516
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 mailbox in MS Exchange via ADO and calculates the mailbox size. I seem to have run into a couple of issues getting python to talk to MS Exchange via ADO though. This is the code i'm using:
852
28239
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 my general education. Mark
3
7194
by: Yusniel | last post by:
Hi friends. Someone know how to work with python and exchange server?.
1
1061
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 of the authentication that you are attempting go, it sounds like you want to use ephemeral DH key exchange. This is something which is on my list to figure out. ;) Jean-Paul
3
3918
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 h:\firm_name \yyyymmdd.csv . Would Python be a good tool to automate the process of saving reports, or would it be more convenient to use a Microsoft proprietary language such as VB or C#? Of course one factor is one's relative competence with the...
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.