Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Sparky1963  
#1 Posted : Wednesday, November 11, 2020 9:48:30 PM(UTC)
Sparky1963

Rank: Newbie

Groups: Registered
Joined: 11/11/2020(UTC)
Posts: 2
United States
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
ivan  
#2 Posted : Friday, November 13, 2020 5:58:40 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,153

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
Sparky1963  
#3 Posted : Friday, November 13, 2020 11:31:04 PM(UTC)
Sparky1963

Rank: Newbie

Groups: Registered
Joined: 11/11/2020(UTC)
Posts: 2
United States
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.
ivan  
#4 Posted : Saturday, November 14, 2020 5:27:27 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,153

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Originally Posted by: Sparky1963 Go to Quoted Post
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.
Users browsing this topic
Guest
Similar Topics
team time trial in Ponferrada as a multiple-rider crash resulted in a DNF against (EASendMail SMTP Component - .NET Version)
by Guest 12/2/2014 7:19:12 PM(UTC)
Forum Jump  
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.131 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.