Results 1 to 4 of 4

Thread: [RESOLVED] POP3 Email Reader

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] POP3 Email Reader

    I am trying to write a class to read email from a pop3 server and I am trying to read information from my gmail account. But everytime I get to the line indicated I get the following error I am not sure how to combat this problem.


    "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host."

    Here is the code I am trying to make the initial connection.
    VB Code:
    1. Private _Server As TcpClient
    2.     Private _NetStrm As NetworkStream
    3.     Private _ReadStrm As StreamReader
    4.     Private _IncommingData As Byte()
    5.     Private _Password as String
    6.     Private _Username as String
    7.     Private Const CRLF As String = vbCrLf
    8.  
    9.     Public Function Connect() As Boolean
    10. ' create server POP3 with port 110
    11.         _Server = New TcpClient("pop.gmail.com", 110)
    12.  
    13.         Try
    14.             _NetStrm = _Server.GetStream()          
    15.             _ReadStrm = New StreamReader(_Server.GetStream())
    16.  
    17.             'Login Process
    18.             Dim Data As String = "USER " & _Username & CRLF
    19.  
    20.             _IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
    21.             _NetStrm.Write(_IncommingData, 0, _IncommingData.Length)
    22.  
    23.             Data = "PASS " & _Password & CRLF
    24.             _IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
    25.             _NetStrm.Write(_IncommingData, 0, _IncommingData.Length)'Error Here
    26.  
    27.             'Send STAT command to get information ie: number of mail and size
    28.             Data = "STAT" + CRLF
    29.             _IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
    30.             _NetStrm.Write(_IncommingData, 0, _IncommingData.Length)
    31.  
    32.         Catch ex As Exception
    33.             Return False
    34.         End Try
    35.         Return True
    36. End Function

    Thanks In Advance

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Junior Member
    Join Date
    May 2005
    Location
    California
    Posts
    22

    Re: POP3 Email Reader

    Unless they've recently changed things, GMail requires that you use a secure (SSL/TLS) connection. They also require implicit SSL and don't support the STLS command, which means it doesn't support secure connections over the standard port 110; you have to connect on port 995.
    Mike Stefanik
    sockettools.com

  3. #3

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: POP3 Email Reader

    Hmm let me give that a wing

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  4. #4

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: POP3 Email Reader

    Oh that is fantastic thanks Mike

    This bit of extra code made it work along with port change

    VB Code:
    1. _Strm = New Net.Security.SslStream(_Server.GetStream())
    2.             DirectCast(_Strm, Net.Security.SslStream).AuthenticateAsClient(_PopServ)

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width