Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Monitoring an MS Exchange mailbox

Reply
Thread Tools

RE: Monitoring an MS Exchange mailbox

 
 
Tim Golden
Guest
Posts: n/a
 
      12-30-2003
>From: Lindstrom Greg - glinds [(E-Mail Removed)]
>
>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
__________________________________________________ ______________________

 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      12-30-2003
Tim Golden <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> >From: Lindstrom Greg - glinds [(E-Mail Removed)]
> > [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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot send mail from Exchange 2007 mailbox to Exchange 2003 mailb =?Utf-8?B?am9zdWU=?= MCSE 3 08-15-2007 12:02 PM
how does exchange determine which server hosts a users mailbox? eddiec MCSE 1 01-31-2005 04:34 AM
Creating Exchange Mailbox - Steve - ASP .Net 1 06-15-2004 01:36 PM
Monitoring an MS Exchange mailbox Lindstrom Greg - glinds Python 2 12-30-2003 09:46 AM
Monitoring Exchange 2000 Mailbox MC Computer Support 2 12-10-2003 07:49 AM



Advertisments