Blog Post

Exchange Team Blog
1 MIN READ

Automatically delete and archive badmail

The_Exchange_Team's avatar
May 25, 2004

Ever had problems with your badmail?  Need to keep them under control but cannot completely disable them for various reasons?  If so, the Badmail Deletion and Archival script is for you!  Use the Badmail Deletion and Archival script to schedule the automatic deletion or archival of files in the badmail directory of specified SMTP virtual servers on Exchange 2000 or Exchange 2003 servers or clusters running on a Windows 2000 Server or a Windows Server 2003. With this script, you can ensure that the size of the badmail directory does not exceed specific size limits and eliminate the administrative overhead of manually archiving or deleting these files.  This script is designed to run as a scheduled event at non-peak usage hours, when mail flow and network traffic is low.

 

Installation is easy, just download the script to any folder and schedule it via Scheduled Tasks to run periodically.

- Alvin Mok

Published May 25, 2004
Version 1.0
  • Thank you, thank you, thank you. It's about time.
    I never understood what the point of saving the BadMail was anyway. It only exists because it couldn't be delivered. If it can't be delivered it is either mis-addressed or (more likely) spam for ex-employees. I can't imagine any admin with the time to look through BadMail for "good" messages.
  • Thanks for the Script as it is need in my location due to Management required to archive all mails whether bad or not .
  • The Badmail folder is invaluable when using a server to send bulk e-mail to a newsgroup. You can write a script to look through the Badmail folder to automatically unsubscribe bad e-mail addresses so you aren't sending 200,000 bad e-mails every time you do a mailing.
  • We have afew gigabyte bad mail size at exchange2000 and it takes alot to delete, can this script work for this big size? or what is the limit of this scrip can easyly delete ? for several hours we are waiitng win2000 to delete this folder

    Thanks.
  • Can't think of any reason why this wouldn't scale reasonably well. The script simply deletes every file it can find in a loop, the only consequence of having a lot of files is that this loop runs longer. The issue is not necessarily whether the script scales, this is handled by the file system.

    Now, running a WSF script introduces a more overhead than writing a straight-up CMD shell script. Regardless whether you use the script or a shell script, deleting a large amount of files is expensive and can be potentially very time consuming, so this is why we suggest that any work like this is scheduled for low-peak hours. This should be treated akin to database maintenance.

    To minimize the cost of potentially large (multi gigabyte) badmail payloads, we encourage:
    - Having more frequent badmail cleanup sweeps, trying to stay on top of the pile as it grows a bit more proactively.
    - If you want to keep a larger amount of badmail (a few gigabytes) before sweeping, I'd suggest sweeping more with the archive functionality. Have a separate bin to dump your badmail every few days and then every so often have this bin be purged. If this is, say, another machine on your network, you can offload the cost of cleaning onto another server.
    - Disabling badmail altogether (which is default in Exchange 2003 SP1, but can be done through the script).

    Hope that helps!