Archived Forum Post

Index of archived forum posts

Question:

No Socket Exists for Sending (error message)

Aug 15 '12 at 19:04

I am trying to get all emails from my hotmail account. There are about 27744 mails in Inbox. I am trying to get all emails through POP3.

I am capturing 10 mails at a time. I am following this tutorial: http://www.example-code.com/vbdotnet/pop3_readLargeMailbox.asp

Now after getting 2400 mails it is showing me an error.

No Socket exists for Sending (2b)

How to resolve this problem? I am trying for a long time without any success.


Answer

The "No socket exists for sending" error message means one of the following:

  1. A connection was never made to the server (SMTP, POP3, IMAP, FTP, etc.) and therefore the client-side has no valid connected socket.
  2. At some prior point, a Chilkat method call resulted in the loss of the connection, but the application did not check the status return of the method call. The error needs to be handled at the point of failure. Once the connection is lost, the Chilkat object is in the disconnected state, and a subsequent method call (that requires a connection) will fail with a message in the LastErrorText saying "No socket exists for sending".

Answer

I think in my case the option 2 is the cause. The connection is somehow lost. Can you guide me how to check connection and if lost then reconnect. Here is the code i am using:

    Dim mailman As New Chilkat.MailMan()

'  Any string argument automatically begins the 30-day trial.
Dim success As Boolean
success = mailman.UnlockComponent("My-Registered-Unlock-Code")
If (success <> true) Then
    MsgBox("Component unlock failed")
    Exit Sub
End If

'  Set the POP3 server's hostname
mailman.MailHost = "mail.chilkatsoft.com"

'  Set the POP3 login/password.
mailman.PopUsername = "myLogin"
mailman.PopPassword = "myPassword"

'  First, get the list of UIDLs for all emails in the mailbox.
Dim sa As Chilkat.StringArray
sa = mailman.GetUidls()
Dim i As Long
Dim numEmails As Long
numEmails = sa.Count

'  Download the emails in chunks of 10 emails each.
Dim chunkBeginIdx As Long
chunkBeginIdx = 0
Dim chunkEndIdx As Long
chunkEndIdx = 9
If (chunkEndIdx >= numEmails) Then
    chunkEndIdx = numEmails - 1
End If

Dim saChunk As New Chilkat.StringArray()
While (chunkEndIdx < (numEmails - 1))

    '  Build a chunk of 10 UIDLs.
    saChunk.Clear()
    For i = chunkBeginIdx To chunkEndIdx
        saChunk.Append(sa.GetString(i))
    Next

    '  Display the UIDLs in this chunk...
    Dim chunkStr As String
    chunkStr = saChunk.SaveToText()
    TextBox1.Text = TextBox1.Text & chunkStr & vbCrLf
    TextBox1.Text = TextBox1.Text & "----" & vbCrLf & vbCrLf

    '  Download this chunk of email from the POP3 server.
    Dim bundle As Chilkat.EmailBundle
    bundle = mailman.FetchMultiple(saChunk)
    If (bundle Is Nothing ) Then
        MsgBox(mailman.LastErrorText)
        Exit Sub
    End If

    '  Process the bundle...
    '  (your application's processing code goes here...)

    '  Get the next chunk...
    chunkBeginIdx += 10
    If (chunkBeginIdx >= numEmails) Then
        Exit For
    End If

    chunkEndIdx += 10
    If (chunkEndIdx >= numEmails) Then
        chunkEndIdx = numEmails - 1
    End If
End While

Answer

I updated the online example. The call to mailman.GetUidls should be checked, like this:

'  First, get the list of UIDLs for all emails in the mailbox.
Dim sa As Chilkat.StringArray
sa = mailman.GetUidls()
If (sa Is Nothing ) Then
    TextBox1.Text = TextBox1.Text & mailman.LastErrorText & vbCrLf
    Exit Sub
End If


Answer

Thanks for the fix. But i can not understand. The problem is while extracting mails the connection is somehow lost. How we can check whether an active connection is working or not? And if not working then how to reconnect and resume the job. And it should be in While.. End While loop. Please confirm.

Thanks.


Answer

Hi, Any update?


Answer

Use the DebugLogFilePath property to create a log file that contains the LastErrorText's of every Chilkat method call (for the imap object instance). Then examine the log file to find out where the connection becomes lost. You should see the connection become lost, and then each subsequent LastErrorText will indicate that "no socket exists".

Also, make sure you are using the very latest version (v9.3.2).

Finally, whenever posting a LastErrorText, make sure to include the entire amount, including the information at the beginning.