Rank: Newbie
Groups: Registered
Joined: 11/11/2020(UTC)
Posts: 2
Location: Utah
I wrote a VB.net class around the EAGetmail library. The class has a built in system to check the email at regular intervals in the background. The function that reads and formats the received mail from a POP3 server crashes at least 3 times a day. Under development mode I can continue execution and the DLL will connect and move on. I added a Try-Catch block around it to try to trap and handle it, but that doesn't work. I also added a piece of code that pings the POP3 server to make sure it can be found. If this were a standalone application and running out of the Development environment, this would cause a catastrophic failure. Where this app runs on its own without interaction, this crash is unacceptable. I wondered if the POP3 server was not accepting connections when this occurs. Any help I could get would be greatly appreciated. I have pasted the function below. Public Function ReceivePOP3Messages() As EmailMessageStructure() Dim Temp() As EmailMessageStructure = Nothing Dim Counter As Integer = -1 Dim ServerOpened As Boolean = False Dim Count As Integer = 0 Dim Content As EmailMessageStructure = Nothing Dim Messages() As EAGetMail.MailInfo = Nothing Dim EMail As EAGetMail.Mail = Nothing Dim Abort As Boolean = False Dim Index As Integer = -1 Dim Found As Boolean = False Do Application.DoEvents() Loop Until (Not cSending) cReceiving = True Do Found = cSimplePingHost(cPOP3MailServer.Server) Application.DoEvents() If (Not Found) Then cDelay(1000) End If Loop Until (Found) Try cPOP3MailClient.Connect(cPOP3MailServer) Catch ex As EAGetMail.MailServerException RaiseEvent POP3Errors("Mail Initialization Error: " & ex.ErrorMessage) Abort = True End Try If (Not Abort) Then ServerOpened = cPOP3MailClient.Connected If (ServerOpened) Then Messages = cPOP3MailClient.GetMailInfos Count = Messages.Length If (Count > 0) Then For Each Message In Messages Index += 1 EMail = cPOP3MailClient.GetMail(Message) Content = cGetMailMessage(EMail, Index) If (Not IsNothing(Content)) Then Counter += 1 ReDim Preserve Temp(Counter) Temp(Counter) = Content 'cMarkForDelete(i) End If Content = Nothing If (cPOP3MailServer.Protocol = EAGetMail.ServerProtocol.Imap4) Then cPOP3MailClient.MarkAsRead(Message, True) End If cPOP3MailClient.Delete(Message) Next End If If (cPOP3MailServer.Protocol = EAGetMail.ServerProtocol.Imap4) Then cPOP3MailClient.Logout() End If cPOP3MailClient.Quit() End If End If cReceiving = False Return Temp End Function
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,152
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Hi, because EAGetMail may throw different exception (networking connection or server exception), so you should catch the exception like this, otherwise unhandled exception will crash your application.
Code:
Try
cPOP3MailClient.Connect(cPOP3MailServer)
If (Not Abort) Then
ServerOpened = cPOP3MailClient.Connected
If (ServerOpened) Then
Messages = cPOP3MailClient.GetMailInfos
Count = Messages.Length
If (Count > 0) Then
For Each Message In Messages
Index += 1
EMail = cPOP3MailClient.GetMail(Message)
Content = cGetMailMessage(EMail, Index)
If (Not IsNothing(Content)) Then
Counter += 1
ReDim Preserve Temp(Counter)
Temp(Counter) = Content
'cMarkForDelete(i)
End If
Content = Nothing
If (cPOP3MailServer.Protocol = EAGetMail.ServerProtocol.Imap4) Then
cPOP3MailClient.MarkAsRead(Message, True)
End If
cPOP3MailClient.Delete(Message)
Next
End If
If (cPOP3MailServer.Protocol = EAGetMail.ServerProtocol.Imap4) Then
cPOP3MailClient.Logout()
End If
cPOP3MailClient.Quit()
End If
End If
Catch ex As Exception
RaiseEvent POP3Errors("Mail Initialization Error: " & ex.ErrorMessage)
Abort = True
End Try
Rank: Newbie
Groups: Registered
Joined: 11/11/2020(UTC)
Posts: 2
Location: Utah
Thanks for your suggestion, but the crash point is ALWAYS the "cPOP3MailClient.Connect(cPOP3MailServer)" line. I have been watching it today and it hasn't crashed today. The next time it does, I will be sure to capture the message of the exception and post it so you can see what is happening.
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,152
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Originally Posted by: Sparky1963 Thanks for your suggestion, but the crash point is ALWAYS the "cPOP3MailClient.Connect(cPOP3MailServer)" line. I have been watching it today and it hasn't crashed today. The next time it does, I will be sure to capture the message of the exception and post it so you can see what is happening.
In your old codes, you only catch MailServerException, this exception will throw with negative server response, but you didn't catch networking connection or other exception.
Forum Jump
EmailArchitect Support
Email Component Development
- EASendMail SMTP Component - .NET Version
- EASendMail SMTP Component - Windows Store Apps
- EASendMail SMTP ActiveX Object
- EAGetMail POP3 & IMAP4 Component - .NET Version
- EAGetMail POP3 & IMAP4 ActiveX Object
Exchange Server and IIS SMTP Plugin
- DomanKeys/DKIM for Exchange Server and IIS SMTP
- Disclaimer and S/MIME for Exchange Server and IIS
EmailArchitect Email Server
- EmailArchitect Email Server (General)
- EmailArchitect Email Server Development
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.