Re: Deleting sent items from a mailbox

Tech-Archive recommends: Fix windows errors by optimizing your registry



An update, I've found references to do this in C++ by using loaduserprofile()
but how do I do this using VBScript? Through WMI?

Just looking for a pointer in the correct direction.

Thank you.


"Alf" wrote:

I still haven't found any proper references to "load the HKCU hive". Is it as
simple as reading the correct key string for it to be considered loaded or do
I need to actually use reg.exe and load the user's ntuser.dat file?

"Dmitry Streblechenko" wrote:

No, the HKCU hive should be loaded for a non-interactive process, it is not
loaded however if you impersonate a user within your process.
How exactly do you run your code?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Alf" <Alf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D65F6848-B808-4F57-8487-4585615C7912@xxxxxxxxxxxxxxxx
1) Yes, the code is running under the correct user.

2) I can log in as the profilee using Outlook if I log in to the server
using the mailbox's attached NT account as an interactive session. I can
even
log in using this profile in Outlook if the service is still running and
accessing the profile.
I initially tried getting to the sent items folder by using OOM, but that
didn't work because Outlook requires an interactive session before it can
properly start.

3) Yes, my #4 parameter for Session.Login is set to True. When I ran into
this error, I tried setting the #3 parameter (showdialog) to true, and I
get
a prompt saying the profile I would like to use cannot be located and the
select profile box comes up.

I have been searching on the web for solutions to this issue, and I have
seen mentioned that this is because the Windows registry is not loaded for
a
non-interactive session. If this is the case, is there a safe way of
loading
only the part of the registry that is required - the part where the
profiles
are stored?

The truth, I'm not really comfortable messing about with the registry,
especially on these systems.

"Dmitry Streblechenko" wrote:

You are sure your code is running under the same Windows user identity as
that service, right? Can you log to the profilee with Outlook?
Did you remember to change the parameter #4 in Session.Logon (NewSession)
to
true?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Alf" <Alf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E3441049-7828-4ECA-98BD-CD47EE97284D@xxxxxxxxxxxxxxxx
No, it still doesn't work.


"Dmitry Streblechenko" wrote:

Does it succeed if you stop the service that uses the same profile
first?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Alf" <Alf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7FF3F9DB-2AB6-4A04-9DCB-1CF9A2C18A2B@xxxxxxxxxxxxxxxx
An addition, I used the following code when trying to log in to the
local
profile:

Session.Logon "<profile_name_here>", "", False, True, 0, False

"Alf" wrote:


Hi Dmitry,

I get this CDO error if I call Session.Login and giving it a
profile
name
to
use: "MAPI_E_LOGON_FAILED(80040111)"


"Dmitry Streblechenko" wrote:

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
thee profile that has that PST file or dynamically create a
profile
and
add
the PST file there (MAPI only, no CDO or OOM).
If you are running under the same Windows user identity as that
service, you
should be able to logon to the same profile. What happens when
you
call
Session.Logon specifying the explicit profile name that contains
the
PST
file?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Alf" <Alf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BD119FE6-7614-4A41-BEC3-79533FA6ED06@xxxxxxxxxxxxxxxx
Hi all,

I have a windows service which accesses a mailbox to process
certain
requests. I did not write this service and it is not
configurable.
It
uses
the locally created profile for the mailbox to process received
emails and
puts the processed emails into the Sent Items folder.

Trouble starts when lots of requests are in the mailbox and it
goes
oversize, which stops the service from processing any more
requests.
What
we
usually do is log on to the server where the service is running
using
the
mailbox account and manually delete all of the items in the
sent
items
folder.

I'm trying to replicate that in code, which means running it as
a
non-interactive session, scheduling the script to run under the
mailbox
user.
I'm using VBScript with CDO. Outlook 2000 is installed on the
server
which
is
running Windows 2000. Although I have successfully managed to
log
in
to
exchange to access the mailbox, there is nothing in the Sent
Items
folder.
I'm using a dynamic profile because when I try to access the
local
mailbox
profile, I get the CDO error "MAPI_E_LOGON_FAILED(80040111)".

What are my options to gain access to the sent items of the
mailbox?
I believe the sent items are stored locally in PST files is
that
correct,
and only by logging in to the mailbox's local profile will I
get
the
sent
items? How can I properly load the local profile?

Here's my code so far:
'Declare constants for CDO folder enums
Const CdoDefaultFolderSentItems = 3
Const CdoDefaultFolderDeletedItems = 4


Set objDictionary = CreateObject("Scripting.Dictionary")

'Get a new MAPI Object
Set objSession = CreateObject("MAPI.Session")

Err.Clear
On Error Resume Next

'Get a new MAPI Session by logging in
objSession.Logon "", "", False, True, 0, False,
"server_name_here"
&
vbLf
&
Wscript.Arguments(1)

If Err.Number <> 0 Then
'write to log error cause
Else
Err.Clear
Set objSentItems =
objSession.GetDefaultFolder(CdoDefaultFolderSentItems)
If Err.Number <> 0 Then
'write to log error cause
Else
Set colItems = objSentItems.Messages

Set objMessage = colItems.GetFirst()

Do While Not (objMessage is nothing)
'code to add mail item id into dictionary object

Set objMessage = colItems.GetNext()
Loop

'Rest of code loops through the dictionary object and
calls
the
delete method of every object
End If

End If

objSession.Logoff

Set objSession = nothing
Set objDictionary = nothing
Set objSentItems = nothing
Set colItems = nothing
Set objMessage = nothing

Thanks in advance for any advice.

Best Regards,
Alf













.



Relevant Pages

  • Re: Searching items in non-visible folder?
    ... Then you most definitely don't have CDO installed on that system. ... expand the Outlook section and ensure that Collaboration Data ... >> If you logon using an existing profile, ... >>> items in the folder looking for the messages that I want? ...
    (microsoft.public.outlook.program_forms)
  • Re: Deleting sent items from a mailbox
    ... OutlookSpy - Outlook, CDO ... "Dmitry Streblechenko" wrote: ... accessing the profile. ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Deleting sent items from a mailbox
    ... Can you log to the profilee with Outlook? ... OutlookSpy - Outlook, CDO ... I get this CDO error if I call Session.Login and giving it a profile ... I have a windows service which accesses a mailbox to process ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Deleted Item not in deleted folder?
    ... you will get errors trying to instantiate a MAPI.Session if CDO 1.21 ... A piggy-back logon won't do you any good at all if Outlook isn't running. ... Or you can use the profile name if you know it: ...
    (microsoft.public.outlook.program_vba)
  • Re: Is it possible to show shared Contact on the Address Book?
    ... "Profile" here means Outlook profile, ... mailbox, not your own mailbox. ... Use the More Settings button on the Exchange accounts ...
    (microsoft.public.outlook.contacts)