Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Monitoring an MS Exchange mailbox

1 view
Skip to first unread message

Lindstrom Greg - glinds

unread,
Dec 29, 2003, 3:38:38 PM12/29/03
to pytho...@python.org
I have written a script to monitor my MS Exchange mailbox for certain
messages and post information to an MS SQL Server Database. Everything
works great except that each time I run the script I am prompted by Windows
to choose the profile of the mailbox via a dialog box. I'd like to run the
script every hour, so this is not good.

Is there any way to either specify the profile or accept the default?

Thanks for any help you can send my way.

--greg

**********************************************************************
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.


Martin v. Loewis

unread,
Dec 29, 2003, 8:03:38 PM12/29/03
to
Lindstrom Greg - glinds wrote:
> I have written a script to monitor my MS Exchange mailbox for certain
> messages and post information to an MS SQL Server Database. Everything
> works great except that each time I run the script I am prompted by Windows
> to choose the profile of the mailbox via a dialog box. I'd like to run the
> script every hour, so this is not good.
>
> Is there any way to either specify the profile or accept the default?
>

Certainly. Just pass the profile name as an argument to the function
opening the connection to exchange.

Regards,
Martin

Tim Howarth

unread,
Dec 30, 2003, 4:46:26 AM12/30/03
to
In message <mailman.20.10727302...@python.org>

Lindstrom Greg - glinds <Greg.Li...@acxiom.com> wrote:

> I have written a script to monitor my MS Exchange mailbox for certain
> messages and post information to an MS SQL Server Database.

> Is there any way to either specify the profile or accept the default?

I don't know about that but I do something similar using imaplib - it
used to connect to a non-Exchange email server, I left it as it was
when we switched to Exchange and it continued to work (obviously with
IMAP enabled in Exchange).


--
___
|im ---- ARM Powered ----

Tim Golden

unread,
Dec 30, 2003, 5:17:06 AM12/30/03
to Lindstrom Greg - glinds, pytho...@python.org
>From: Lindstrom Greg - glinds [mailto:Greg.Li...@acxiom.com]

>
>I have written a script to monitor my MS Exchange mailbox for certain
>messages and post information to an MS SQL Server Database. Everything
>works great except that each time I run the script I am
>prompted by Windows
>to choose the profile of the mailbox via a dialog box.
>
>Is there any way to either specify the profile or accept the default?

You have three options that I can think of. I assume you're using CDO
(ie the MAPI.Session COM object). Each of the techniques should leave
you with a working session. The Logon method has a number of other
parameters controlling, for example, whether a dialog box should be
displayed if the logon fails and so on. Consult MSDN for details: it's
quite lucid on the subject.

1) Hardcode a profile name with the options you need and pass it in:

<code>
import win32com.client
session = win32com.client.Dispatch ("MAPI.Session")
session.Logon (ProfileName="Tim Golden")
# obviously replace my name by the
# display name of your profile, the
# one that appears in the dialog box
</code>

2) If you don't have that much control, find the user's default
profile and use that:

<code>
import win32com.client
import _winreg

reg1 = "\\".join ([
"Software",
"Microsoft",
"Windows NT",
"CurrentVersion",
"Windows Messaging Subsystem",
"Profiles"
])
reg2 = "\\".join ([
"Software",
"Microsoft",
"Windows Messaging Subsystem",
"Profiles"
])

try:
key = _winreg.OpenKey (_winreg.HKEY_CURRENT_USER, reg1)
except:
try:
key = OpenKey (_winreg.HKEY_CURRENT_USER, reg2)
except:
key = None

if key:
try:
default_profile, should_be_string = \
_winreg.QueryValueEx (key, "DefaultProfile")
except:
default_profile = ""

session = win32com.client.Dispatch ("MAPI.Session")
session.Logon (ProfileName=default_profile)
</code>

3) One other option, with limitations, is to construct a
profile info string on the fly, and pass that to the
logon method:

<code>
import win32com.client

EXCHANGE_SERVER = "xyz"
MAILBOX_NAME = "tim.golden"
#
# Obviously replace the server and
# mailbox names to suit.
#

session = win32com.client.Dispatch ("MAPI.Session")
session.Logon ("%s\n%s" % (EXCHANGE_SERVER, MAILBOX_NAME))
</code>

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Tim Golden

unread,
Dec 30, 2003, 8:51:04 AM12/30/03
to pytho...@python.org
>From: Lindstrom Greg - glinds [mailto:Greg.Li...@acxiom.com]
>

[... snip 3 possibilities ...]

>Thank-you! This fixes the problem; I'm off and running.

Glad to hear it. Sometimes it's the small things...

>one of the reasons I prefer Python over Perl
>is that the Python community does not appear
>to be as hostile towards MS

I'm not familiar with the Perl community, but my experience
of the Python one is that it is just about as sane and
helpful as you're going to get anywhere. That's not to say
that you won't get acerbic responses to foolish questions;
but you'll probably find that someone will answer them
anyway!

>I'm assuming MSDN is Microsoft Developer's Network?
>Is that a subscription service?

Sorry. I assumed... It probably exists in some enhanced
form if you pay, but for most of us, it's the result of
Googling, eg, for MAPI CDO session, and hitting
[I'm Feeling Lucky]. (This URL may get truncated/wrapped;
it's 109 chars long).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_o
lemsg_starting_a_cdo_session.asp


> Now that I can monitor the mailbox, I'd like to delete message
> once they've been processed and would like to see the documentation
> on how to do it as well as other things.

Googling for CDO delete message gives this as the second hit
(again, a long URL):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_o
lemsg_delete_method_message.asp

If you need examples, let me know. I'm trying to put together a
Python CDO examples webpage, but keep getting sidetracked.

Tim Golden

unread,
Dec 30, 2003, 9:30:38 AM12/30/03
to
Tim Golden <tim.g...@viacom-outdoor.co.uk> wrote in message news:<mailman.34.10727798...@python.org>...

> >From: Lindstrom Greg - glinds [mailto:Greg.Li...@acxiom.com]
> > [snip request to avoid logon prompt when attaching to MS Exchange]

>
>
> You have three options that I can think of.
>

[snip examples (1) & (2)]

> 3) One other option, with limitations, is to construct a
> profile info string on the fly, and pass that to the
> logon method:
>
> <code>
> import win32com.client
>
> EXCHANGE_SERVER = "xyz"
> MAILBOX_NAME = "tim.golden"
> #
> # Obviously replace the server and
> # mailbox names to suit.
> #
>
> session = win32com.client.Dispatch ("MAPI.Session")
> session.Logon ("%s\n%s" % (EXCHANGE_SERVER, MAILBOX_NAME))
> </code>

Oops. That last line should read:

session.Logon (ProfileInfo="%s\n%s" % (EXCHANGE_SERVER, MAILBOX_NAME))

Sorry; that's the only one I didn't cut-and-paste into a
Python session before posting. Just goes to show...

TJG

0 new messages