RE: Monitoring an MS Exchange mailbox

Discussion in 'Python' started by Tim Golden, Dec 30, 2003.

  1. Tim Golden

    Tim Golden Guest

    >From: Lindstrom Greg - glinds [mailto:]
    >
    >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, Dec 30, 2003
    #1
    1. Advertising

  2. Tim Golden

    Tim Golden Guest

    Tim Golden <> wrote in message news:<>...
    > >From: Lindstrom Greg - glinds [mailto:]
    > > [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
     
    Tim Golden, Dec 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. - Steve -

    Creating Exchange Mailbox

    - Steve -, Jun 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    581
    Trevor Benedict R
    Jun 15, 2004
  2. Lindstrom Greg - glinds

    Monitoring an MS Exchange mailbox

    Lindstrom Greg - glinds, Dec 29, 2003, in forum: Python
    Replies:
    2
    Views:
    357
    Tim Howarth
    Dec 30, 2003
  3. Suman
    Replies:
    0
    Views:
    681
    Suman
    Aug 16, 2006
  4. KDawg44
    Replies:
    4
    Views:
    1,249
    Tim Golden
    Oct 12, 2007
  5. Tommy Holm Jakobsen

    Extract Exchange 2003 mailbox (PST) from C#/ASP.NET?

    Tommy Holm Jakobsen, Jul 9, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    821
    Tommy Holm Jakobsen
    Jul 10, 2008
Loading...

Share This Page