Monday, March 10, 2008

Script to delete email in inbox and junk email folders

well
so many corporate customers were asking me for such a thing, users are keeping so many emails in their junk email folder and their inbox,
so how can delete them.
i searched and i found a great one @ glen scale's blog http://gsexdev.blogspot.com

i customized the script to prompet for user name and i will provide 2 scripts to delete email in inbox and junk email folders

to delete emails in inbox:
-----
ID = InputBox("Target what user?", "user Name?", _ "user1")ID = "file://./backofficestorage/yourdomain.com/MBX/" & ID & "/inbox"mailboxurl = IDset Rec = CreateObject("ADODB.Record")set Rs = CreateObject("ADODB.Recordset")Set Conn = CreateObject("ADODB.Connection")Conn.Provider = "ExOLEDB.DataSource"Rec.Open mailboxurl, ,3SSql = "SELECT ""DAV:href"", ""DAV:contentclass"" FROM scope('shallow traversal of """ & mailboxurl & """') " SSql = SSql & " WHERE (""urn:schemas:httpmail:datereceived"" < CAST(""" & isodateit(now()-0) & """ as 'dateTime')) AND ""DAV:isfolder"" = false" SSql = SSql & " AND ""DAV:contentclass"" = 'urn:content-classes:message'"Rs.CursorLocation = 2 'adUseServer = 2, adUseClient = 3rs.open SSql, rec.ActiveConnection, 3while not rs.eofrs.delete 1rs.movenextwendrs.close
function isodateit(datetocon)strDateTime = year(datetocon) & "-"if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"strDateTime = strDateTime & Month(datetocon) & "-"if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"strDateTime = strDateTime & Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"isodateit = strDateTimeend function
-----
Junk email delete script
-----
ID = InputBox("Target what user?", "user Name?", _ "user1")ID = "file://./backofficestorage/yourdomain.com/MBX/" & ID & "/junk e-mail"
mailboxurl = IDset Rec = CreateObject("ADODB.Record")set Rs = CreateObject("ADODB.Recordset")Set Conn = CreateObject("ADODB.Connection")Conn.Provider = "ExOLEDB.DataSource"Rec.Open mailboxurl, ,3SSql = "SELECT ""DAV:href"", ""DAV:contentclass"" FROM scope('shallow traversal of """ & mailboxurl & """') " SSql = SSql & " WHERE (""urn:schemas:httpmail:datereceived"" < CAST(""" & isodateit(now()-0) & """ as 'dateTime')) AND ""DAV:isfolder"" = false" SSql = SSql & " AND ""DAV:contentclass"" = 'urn:content-classes:message'"Rs.CursorLocation = 2 'adUseServer = 2, adUseClient = 3rs.open SSql, rec.ActiveConnection, 3while not rs.eofrs.delete 1rs.movenextwendrs.close
function isodateit(datetocon)strDateTime = year(datetocon) & "-"if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"strDateTime = strDateTime & Month(datetocon) & "-"if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"strDateTime = strDateTime & Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"isodateit = strDateTimeend function
----

No comments: