RE: Monitoring an MS Exchange mailbox

From: Tim Golden (tim.golden_at_viacom-outdoor.co.uk)
Date: 12/30/03


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
________________________________________________________________________



Relevant Pages

  • Re: Deleting sent items from a mailbox
    ... If you are using a dynamic profile, you are seeing the Exchange mailbox. ... If the messages in question are in a PST file, you need to either log to ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Outlook Messages are not leaving exchange for one user
    ... I decided to follow your advice and to just create a new user profile for this user, I didnt have to worry about doing the ESM mailbox changes. ... and log onto the computer with the new users domain account. ... If you accept that the user is not going to be a local administrator, then start outlook and provide the details to configure it to connect to Exchange. ...
    (microsoft.public.windows.server.sbs)
  • Re: Outlook Messages are not leaving exchange for one user
    ... I decided to follow your advice and to just create a new user profile for this user, I didnt have to worry about doing the ESM mailbox changes. ... and log onto the computer with the new users domain account. ... If you accept that the user is not going to be a local administrator, then start outlook and provide the details to configure it to connect to Exchange. ...
    (microsoft.public.windows.server.sbs)
  • Re: outlook 2002 contacts sharing
    ... Create profile that logs onto other mailbox. ... Set distinctive address book name for contacts folder. ... Shut down Outlook. ... Modify that same profile to add the other mailbox as a secondary mailbox. ...
    (microsoft.public.outlook.contacts)
  • Re: Deleting sent items from a mailbox
    ... mailbox. ... OutlookSpy - Outlook, CDO ... accessing the profile. ...
    (microsoft.public.win32.programmer.messaging)