RE: Monitoring an MS Exchange mailbox
From: Tim Golden (tim.golden_at_viacom-outdoor.co.uk)
Date: 12/30/03
- Next message: Phil Hornby: "RE: argument list"
- Previous message: Rene Pijlman: "Re: canonical file access pattern?"
- Maybe in reply to: Lindstrom Greg - glinds: "Monitoring an MS Exchange mailbox"
- Next in thread: Tim Golden: "Re: Monitoring an MS Exchange mailbox"
- Reply: Tim Golden: "Re: Monitoring an MS Exchange mailbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Dec 2003 10:17:06 -0000 To: 'Lindstrom Greg - glinds' <Greg.Lindstrom@acxiom.com>
>From: Lindstrom Greg - glinds [mailto:Greg.Lindstrom@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
________________________________________________________________________
- Next message: Phil Hornby: "RE: argument list"
- Previous message: Rene Pijlman: "Re: canonical file access pattern?"
- Maybe in reply to: Lindstrom Greg - glinds: "Monitoring an MS Exchange mailbox"
- Next in thread: Tim Golden: "Re: Monitoring an MS Exchange mailbox"
- Reply: Tim Golden: "Re: Monitoring an MS Exchange mailbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|