I have this script which should step thru all messages in a mailbox and process them and then delete it until the mailbox is empty
I put in a bunch of messages in the inbox and there were some warnings about the mailbox size in the inbox too.
When it exists the loop it turns out that usually there are still some messages left. also the error does not come at the end of the loop (oMessages.getnext) where I would expect the error when trying to skip beyond the last message but when trying to read the text body of the e-mail, and the mailbox is not empty sometimes, and the message is having text in the body of the e-mail
here is the script
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "profile","",False,True,-1,True
Set oFolder = oSession.Inbox
Set oMessages = oFolder.Messages
set oMail = oMessages.getfirst
If Err <> 0 then
msgbox("error opening mailbox")
logfilefs.close
Wscript.quit
end if
Do
StrBody = oMail.text
If Err <> 0 then
msgbox("error textbody " & err.number & " - " & Err.description)
Else
If Instr(StrBody,"Backup Operation") <> 0 Then
'***********************
'*** process message ***
'***********************
oMail.Delete
Set oMail = Nothing
Else
'not a backup message ignoring entry
oMail.Delete
set oMail = Nothing
End If
End If
StrBody = ""
Set oMail = oMessages.getnext
Loop Until Err <> 0
Err.Clear
logfilefs.writeline("end of Loop. closing paramters")
so : what is the proper way to detect if I am at the last message ?
second question : why does the error occur at the : StrBody = oMail.text part while the mailbox is not empty ??? (not sure but I got the impression it was giving the error at oMail.text when processing the mailbox size warnings), but next time I would execute the script, it would process it (just delete it) and move on... after 3 times executing the script, the mailbox is realy empty....
Question 3 : why do I not process all the messages in one go, how come it stops at this error while the mailbox is not empty
I put in a bunch of messages in the inbox and there were some warnings about the mailbox size in the inbox too.
When it exists the loop it turns out that usually there are still some messages left. also the error does not come at the end of the loop (oMessages.getnext) where I would expect the error when trying to skip beyond the last message but when trying to read the text body of the e-mail, and the mailbox is not empty sometimes, and the message is having text in the body of the e-mail
here is the script
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "profile","",False,True,-1,True
Set oFolder = oSession.Inbox
Set oMessages = oFolder.Messages
set oMail = oMessages.getfirst
If Err <> 0 then
msgbox("error opening mailbox")
logfilefs.close
Wscript.quit
end if
Do
StrBody = oMail.text
If Err <> 0 then
msgbox("error textbody " & err.number & " - " & Err.description)
Else
If Instr(StrBody,"Backup Operation") <> 0 Then
'***********************
'*** process message ***
'***********************
oMail.Delete
Set oMail = Nothing
Else
'not a backup message ignoring entry
oMail.Delete
set oMail = Nothing
End If
End If
StrBody = ""
Set oMail = oMessages.getnext
Loop Until Err <> 0
Err.Clear
logfilefs.writeline("end of Loop. closing paramters")
so : what is the proper way to detect if I am at the last message ?
second question : why does the error occur at the : StrBody = oMail.text part while the mailbox is not empty ??? (not sure but I got the impression it was giving the error at oMail.text when processing the mailbox size warnings), but next time I would execute the script, it would process it (just delete it) and move on... after 3 times executing the script, the mailbox is realy empty....
Question 3 : why do I not process all the messages in one go, how come it stops at this error while the mailbox is not empty