Check Email Read Errors in Visual Basic

Question:

I am using the code shown in your vb example for reading pop mail. Sometimes I get an error (object doesn't exist ) on the line of code "messagecount=bundle.MessageCount". The line of code that proceeds this one is "set bundle=mailman.TransferMail".

I do not have any code (and your example does not show) to handle problems accessing my mail server. What happens if my mailer server can not be accessed for few minutes? How can I handle this error condition?

Answer:

You should check the return value of TransferMail to see if it failed. Here is how you would do it in Visual Basic:

...
set bundle = mailman.TransferMail()
if (bundle is Nothing) then
	MsgBox mailman.LastErrorText
	Exit Sub
end if
...
You may decide to handle the error differently, but the important thing is to access the last-error information via the properties (LastErrorText, LastErrorHtml, or LastErrorXml) or the method SaveLastError.