Emptying Outlook Deleted Items Folder. 
Author Message
 Emptying Outlook Deleted Items Folder.

All,

Could any one help me out on how I can automatically empty deleted items
folder in MS Outlook?
I am looking for script that would monitor the Deleted Items folder and
delete in on a set interval.

Thanks for any help



Mon, 28 Jul 2003 11:11:26 GMT  
 Emptying Outlook Deleted Items Folder.
Siva,

This example uses CDO to clean out the trash folder and is written in
VBScript as a Windows Script Host script.

Here you go:

--

Dim oSession, oTrash, oItem

Set oSession = CreateObject("MAPI.Session")

oSession.Logon

Set oTrash = oSession.GetDefaultFolder( 4 ) ' the Deleted Items folder

wScript.Echo "There are " & oTrash.Messages.Count & " messages in folder"
for each oItem in oTrash.Messages
  wScript.Echo vbTab & oItem.Subject
next

'Delete all messages
wScript.Echo "Deleting messages..."
oTrash.Messages.Delete

wScript.Echo "There are now " & oTrash.Messages.Count & " messages in
folder"

Set oTrash = Nothing

oSession.Logoff
Set oSession = Nothing

--

If you're using Outlook 2000, I would recommend writing this using the
Outlook object model rather than CDO.  I haven't done any Outlook 2000
development, so I can't help you too much.  The couple of things I can tell
you is that the Deleted Items folder is 3 in the Outlook object model
instead of 4 and that you would use the Items collection, not the Messages
collection.  I also don't think there's a simple one liner like
'oTrash.Messages.Delete', you may have to delete each message individually.

Matt.


Quote:
> All,

> Could any one help me out on how I can automatically empty deleted items
> folder in MS Outlook?
> I am looking for script that would monitor the Deleted Items folder and
> delete in on a set interval.

> Thanks for any help



Tue, 29 Jul 2003 02:52:57 GMT  
 Emptying Outlook Deleted Items Folder.
I tried the script below and I received errors stating could not open MAPI
session.
Any Ideas? I have a 2000 Win2k Box with Outlook 2000 installed.
Thanks in advance.


Quote:
> Siva,

> This example uses CDO to clean out the trash folder and is written in
> VBScript as a Windows Script Host script.

> Here you go:

> --

> Dim oSession, oTrash, oItem

> Set oSession = CreateObject("MAPI.Session")

> oSession.Logon

> Set oTrash = oSession.GetDefaultFolder( 4 ) ' the Deleted Items folder

> wScript.Echo "There are " & oTrash.Messages.Count & " messages in folder"
> for each oItem in oTrash.Messages
>   wScript.Echo vbTab & oItem.Subject
> next

> 'Delete all messages
> wScript.Echo "Deleting messages..."
> oTrash.Messages.Delete

> wScript.Echo "There are now " & oTrash.Messages.Count & " messages in
> folder"

> Set oTrash = Nothing

> oSession.Logoff
> Set oSession = Nothing

> --

> If you're using Outlook 2000, I would recommend writing this using the
> Outlook object model rather than CDO.  I haven't done any Outlook 2000
> development, so I can't help you too much.  The couple of things I can
tell
> you is that the Deleted Items folder is 3 in the Outlook object model
> instead of 4 and that you would use the Items collection, not the Messages
> collection.  I also don't think there's a simple one liner like
> 'oTrash.Messages.Delete', you may have to delete each message
individually.

> Matt.



> > All,

> > Could any one help me out on how I can automatically empty deleted items
> > folder in MS Outlook?
> > I am looking for script that would monitor the Deleted Items folder and
> > delete in on a set interval.

> > Thanks for any help



Tue, 29 Jul 2003 21:08:28 GMT  
 Emptying Outlook Deleted Items Folder.
You probably don't have CDO installed.  It doesn't install by default.  Go
back to Outlook setup and make sure that Collaboration Data Objects is
installed.  You could also look for and register the dll (CDO.DLL).

    C:\Program Files\Common Files\System\Mapi\1033\NT\CDO.DLL
    C:\WINNT\system32\CDO.DLL

--

Matt.


Quote:
> I tried the script below and I received errors stating could not open MAPI
> session.
> Any Ideas? I have a 2000 Win2k Box with Outlook 2000 installed.
> Thanks in advance.



> > Siva,

> > This example uses CDO to clean out the trash folder and is written in
> > VBScript as a Windows Script Host script.

> > Here you go:

> > --

> > Dim oSession, oTrash, oItem

> > Set oSession = CreateObject("MAPI.Session")

> > oSession.Logon

> > Set oTrash = oSession.GetDefaultFolder( 4 ) ' the Deleted Items folder

> > wScript.Echo "There are " & oTrash.Messages.Count & " messages in
folder"
> > for each oItem in oTrash.Messages
> >   wScript.Echo vbTab & oItem.Subject
> > next

> > 'Delete all messages
> > wScript.Echo "Deleting messages..."
> > oTrash.Messages.Delete

> > wScript.Echo "There are now " & oTrash.Messages.Count & " messages in
> > folder"

> > Set oTrash = Nothing

> > oSession.Logoff
> > Set oSession = Nothing

> > --

> > If you're using Outlook 2000, I would recommend writing this using the
> > Outlook object model rather than CDO.  I haven't done any Outlook 2000
> > development, so I can't help you too much.  The couple of things I can
> tell
> > you is that the Deleted Items folder is 3 in the Outlook object model
> > instead of 4 and that you would use the Items collection, not the
Messages
> > collection.  I also don't think there's a simple one liner like
> > 'oTrash.Messages.Delete', you may have to delete each message
> individually.

> > Matt.



> > > All,

> > > Could any one help me out on how I can automatically empty deleted
items
> > > folder in MS Outlook?
> > > I am looking for script that would monitor the Deleted Items folder
and
> > > delete in on a set interval.

> > > Thanks for any help



Wed, 30 Jul 2003 06:53:56 GMT  
 Emptying Outlook Deleted Items Folder.

I modified your script a bit so that it will only delete unread
message in the Deleted Items folder, i.e., junk mail.  Thanks for the
code to start with!  Junk mail expands my PST file, but I don't want
to lose all my deleted messages.

    Jason Fossen

'This will delete unread messages in the Deleted Items folder,
'and ONLY unread messages.  Change the name of your MAPI
'profile from "Default" if that's not what it's named.
'Execute the following line (or similar) to register CDO.DLL on
'Windows 2000:
'"regsvr32 C:\Program Files\Common Files\System\Mapi\1033\NT\CDO.DLL"

Dim oSession, oTrash, oItem, x
Set oSession = WScript.CreateObject("MAPI.Session")
oSession.Logon "Default" 'Name of the desired MAPI profile.
Set oTrash = oSession.GetDefaultFolder( 4 ) 'The Deleted Items folder

x = 0
For Each oItem in oTrash.Messages
        If oItem.Unread Then
                oItem.Delete
                x = x + 1
        End If
Next
WScript.Echo vbCrLf & vbTab & x & " unread messages deleted."

Set oTrash = Nothing
oSession.Logoff
Set oSession = Nothing



Sun, 10 Aug 2003 13:51:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Scheduled task to empty Outlook deleted items

2. Scheduled task to empty Outlook deleted items

3. Outlook Empy 'Deleted Items Folder'

4. Outlook Empy 'Deleted Items Folder'

5. Delete Empty Folders

6. How delete empty folder with vbscript

7. Quick Question about deleting empty folders

8. Delete Empty Folders

9. Outlook -Deleted items

10. How do I delete an Item in a folder programmatically

11. Saving Outlook Form Item into Specified Folder

12. delete empty from droplist?

 

 
Powered by phpBB® Forum Software