[python-win32] Creating a Profile programmatically.

Mark Hammond mhammond at skippinet.com.au
Tue Sep 28 03:17:59 CEST 2004


> I've been using exchange e-mail proiles to Logon( )to Exchange MAPI
Sessions.
> Now I would like to create the Profile programmatically, instead of
clicking
> through the Mail stuff, and have them be persistent across executions of
the

Below is some code that should work.  Python simply wraps most of these MAPI
functions - so your best best is to find the C++ sample code provided by
MS - especially the 'exchange' and 'exchdapi' ones, such as
HrCreateProfileName().  You should even be able to find the MS C++ source to
those "Hr" functions, so see how it can be done at the raw MAPI level.

Depending on your app, you may or may not need a "mailbox agent".

Mark.

ret = exchange.HrCreateProfileName(profileName)
# Attempt to delete the existing profile.
try:
    exchdapi.HrRemoveProfile(profileName)
except pythoncom.error:
    pass

# Occasionally MAPI takes some time to catch up - eg, if this code
# is running from a service and not explicitly marked dependent on
# Exchange, Exchange itself may still be starting.
# You may need to add this code in a loop that handles failure and
# retries.
try:
    exchdapi.HrCreateMailboxAgentProfile(yourProgramName, ret)
except pythoncom.com_error, (hr, desc, exc, arg):
    if hr == winerror.E_ACCESSDENIED:
        # the profile exists, and is in use - just use it.
        pass
    else:
        # all other errors are real errors.
        raise

return ret



More information about the Python-win32 mailing list