Home > Domino Tips > Administrator > Mail > Delete dead mail in mail.boxes
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

MAIL

Delete dead mail in mail.boxes


Brittany Lazarski
02.08.2005
Rating: -3.82- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


VIEW MEMBER FEEDACK TO THIS TIP

If you have several mail.boxes on your server and want your administrator to be able to occasionally run a manual agent to delete all dead messages, this agent will work for you. This agent prints the number of deleted messages to the status bar for each mail.box and then prompts the user with the total deletions from all. Just put this agent in it's own database on the server and manually run it.

  
  Code: Sub Initialize
 Dim nsSession As New NotesSession
 Dim ndbDb As NotesDatabase
 Dim ndcMessages As notesdocumentcollection
 Dim ndocFirstDoc As notesdocument
 Dim ndocNextDoc As notesdocument
 Dim ws As New NotesUIWorkspace
 Dim iCollCount As Integer
 
 
 finalcount=0
 'For all  mail.boxes, find all dead messages 
and delete them.  We have 
3 mail.boxes, so replace 3 with the number you have.
 For i=1 To 3
  iCollCount = 0
  'Get handle to mail.box  
  filename = "mail"+i + ".box"
  Set ndbDb= nsSession.GetDatabase
("serverNameHere", filename)
  If ndbDb.IsOpen Then
   
   'Search string
   Const messages= 
|@Contains(RoutingState; "DEAD")|
   
   'Set document collection
   Set ndcMessages = 
ndbDb.search( messages, Nothing, 0 )
   
   'Grab # of docs to be deleted
   iCollCount = ndcMessages.count
   
   'Delete all documents in the collection, because they 
are dead messages
   ndcMessages.RemoveAll(True)
   
   'Print the number of deleted 
messages to the status  bar
   Print Cstr(iCollCount)+ " dead messages deleted 
from "+filename
  End If
  finalcount = finalcount+iCollCount
 Next 
 
 p = ws.Prompt(PROMPT_OK,  
"Complete", Cstr(finalcount)+" dead messages 
have been deleted.") End Sub

MEMBER FEEDBACK TO THIS TIP

For this tip to work, you must change this line

Const messages= |@Contains(RoutingState; "DEAD")|
to
Const messages= |@Begins(RoutingState; "DEAD")|

You have to do this because all messages have the string "DEAD" (UNDEAD or DEAD)
—Kleber C.

******************************************

I have modified this script, adding two lines to remove email messages with "ERROR" and "User" (for name_user (name_user@domain.com)) not listed in the public Name and Personal Address Book error:

Sub Initialize
     Dim nsSession As New NotesSession
     Dim ndbDb As NotesDatabase
     Dim ndcMessages As notesdocumentcollection
     Dim ndocFirstDoc As notesdocument
     Dim ndocNextDoc As notesdocument
     Dim ws As New NotesUIWorkspace
     Dim iCollCount As Integer

     finalcount=0
 'For all  mail.boxes, find all dead messages and delete them. 
 We have 3 mail.boxes, so replace 3 with the number you have.
     For i=1 To 2
          iCollCount = 0
  'Get handle to mail.box
          filename = "mail"+i + ".box"
          Set ndbDb= nsSession.GetDatabase
("ServerNameHere", filename)
          If ndbDb.IsOpen Then

   'Search string
               Const messages= |@Begins(RoutingState; "DEAD")|
               Const messages2= |@Begins(FailureReason; "User")|
               Const messages3= |@Begins(FailureReason; "Error")|

   'Set document collection
               Set ndcMessages = ndbDb.search
( messages, Nothing, 0 )
               Set ndcMessages2 = ndbDb.search
( messages2, Nothing, 0 )
               Set ndcMessages3 = ndbDb.search
( messages3, Nothing, 0 )

   'Grab # of docs to be deleted
               iCollCount = ndcMessages.count+ 
ndcMessages2.count+ndcMessages3.count

   'Delete all documents in the collection, because
 they are dead messages
               ndcMessages.RemoveAll(True)
               ndcMessages2.RemoveAll(True)
               ndcMessages3.RemoveAll(True)

   'Print the number of deleted messages to the status  bar
               Print Cstr(iCollCount)+ " 
dead messages deleted  from "
+filename
          End If
          finalcount = finalcount+iCollCount
     Next

     p = ws.Prompt(PROMPT_OK,  "Complete", 
Cstr(finalcount)+" dead messages have been deleted.")

End Sub

—Andre A.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Brittany Lazarski. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Mail
Understanding a Lotus Notes Smart Upgrade rollout
Bringing MailRule documents back into view
Use SMTP outbound authentication to relay hosts in Lotus Notes Domino 8
Notes/Domino 6 version of 'Discover Folder'
Five tips to improve email performance
Routing Internet mail from dial-up server via a gateway hub server
Find errors in Notes log through mail database
Five popular administrator tips
Control e-mail with Domino Mail Rules
Expand mail folders by default

Lotus Notes Domino Agents
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007
How to export data from a Lotus Notes database to a CSV file
Must-know Lotus Notes Domino agents -- 10 tips in 10 minutes
Enable or disable scheduled agents without opening the Lotus Notes database design
Creating custom views in Lotus Notes databases
Editing fields in a Lotus Notes view with Ajax
Troubleshooting a scheduled agent not running on a Global Notes Architecture (GNA) server
Can I stop Lotus Domino Server from transforming embedded images into attachments?

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts