Hi Scott, Please see below a cfm page we run as a schedule every night to deal with undeliverable mails.
What this script does is each night move the undeliverable emails back to the spool to try and deliver them (just in case it was network, server etc issues that stopped it from being delivered). Once the emails get past a week old and still can't be delivered it moves them into a permanently rejected folder and will stop trying to send. You can then delete them. It will also send you an email letting you know how many emails have been sent/moved etc. I didn't write this script (but did modify it), however I don't know where I got it from to create the original author. Regards, Mark Picker <!--- Get the mail root directory ---> <cfset MailRoot="#server.ColdFusion.RootDir#\mail"> <!--- set the date trigger to 7, one week ---> <cfset DateTrigger=7> <!--- Read all of the files from the undeliverable directory for processing ---> <cfdirectory action="List" directory="#MailRoot#\undelivr" name="Undeliverables" filter="*.cfmail"> <cfif Undeliverables.RecordCount eq 0> <cfset FilesMoved = 0> <cfset FilesRejected = 0> <cfset UndeliveredMail = QueryNew("FileName, FileSize, LastMod, Status")> <cfset QueryAddRow(UndeliveredMail)> <cfset QuerySetCell(UndeliveredMail, "FileName", "N/A", 1)> <cfset QuerySetCell(UndeliveredMail, "FileSize", "N/A", 1)> <cfset QuerySetCell(UndeliveredMail, "LastMod", "N/A", 1)> <cfset QuerySetCell(UndeliveredMail, "Status", "N/A", 1)> <cfelse> <!--- Set Constants ---> <cfset FilesMoved = 0> <cfset FilesRejected = 0> <cfset UndeliveredMail=QueryNew("FileName, FileSize, LastMod, Status")> <cfset QueryAddRow(UndeliveredMail, Undeliverables.RecordCount)> <cfloop Query="Undeliverables"> <!--- if the last modified date of the file in the undelivr directory is older than the date trigger, or if the file size is 0, delete it. Otherwise, move the file to the spool directory to be resent. ---> <cfif (DateDiff("y", LSDateFormat(DateLastModified), Now()) gt DateTrigger) or (Size eq 0)> <!--- Check to see if the Directory exists. ---> <cfif NOT DirectoryExists("#MailRoot#\Permanently_Rejected\")> <cfdirectory action = "create" directory = "#MailRoot# \Permanently_Rejected" > <cfoutput><p>Your directory has been created.</p></cfoutput> </cfif> <cffile action="Move" source="#MailRoot#\undelivr\#Name#" destination="#MailRoot#\Permanently_Rejected\#Name#"> <cfset QuerySetCell(UndeliveredMail, "FileName", Name, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "FileSize", Size, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "LastMod", DateLastModified, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "Status", "Rejected", Undeliverables.CurrentRow)> <cfset FilesRejected = FilesRejected + 1> <cfelse> <cffile action="Move" source="#MailRoot#\undelivr\#Name#" destination="#MailRoot#\spool\#Name#"> <cfset QuerySetCell(UndeliveredMail, "FileName", Name, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "FileSize", Size, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "LastMod", DateLastModified, Undeliverables.CurrentRow)> <cfset QuerySetCell(UndeliveredMail, "Status", "Rejected", Undeliverables.CurrentRow)> <cfset FilesMoved = FilesMoved+1> </cfif> </cfloop> </cfif> <cfif FilesMoved gte 1 or FilesRejected gte 1> <cfmail query="UndeliveredMail" to=" [EMAIL PROTECTED] " from="[EMAIL PROTECTED]" subject="Undeliverable Mail Report for Server #CGI.Server_Name#"> Total Files Moved to Spool: #FilesMoved# Total Files Rejected: #FilesRejected# These are the files affected: <cfoutput> #Status#: #FileName# (#filesize# bytes, #DateFormat(LastMod,'mm/dd/ yyyy')#) </cfoutput> </cfmail> </cfif> <h2>Task Completed<h2> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~----------~----~----~----~------~----~------~--~---