Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey all, please h-e-l-p!!!
i am working on a new development for my comapny.
the main goal for now is to be able to get access to our support mail which is
Gmail. I am developing the code in vb.net after a bit of research on the web.
very important: when i am trying to access the email, i do that with the next defintions:
1. gmail server address: "pop.gmail.com"
2. user: xxxx@gmail.com
3. password: xxxxxxxx
4. port: 587

and now for the problem:
this Err appears during the connection:
"502 5.5.1 Unrecognized command. es9sm8530250wjd.1 - gsmtp"
i am digging this up for days and still nothing. please please help!!!!
I am attaching the relevent code here>>>
thank you very much,
oron.

-------------------------------------------------------------------------------------------
C#
Imports System
Imports System.Net.Mail
Imports System.Net.Sockets
Imports System.Net.Mail.SmtpClient
Imports System.Text
Imports System.IO


Module POP3Message1

    Dim Server As TcpClient
    Dim NetStrm As NetworkStream
    Dim RdStrm As StreamReader

    Public Function connect() As String
        Dim POP3Account As String
        POP3Account = "pop.gmail.com"
        Try

            Server = New TcpClient(POP3Account.Trim, 587)
            NetStrm = Server.GetStream
            RdStrm = New StreamReader(Server.GetStream)
        Catch exc As Exception
            MsgBox(exc.Message)

            Exit Function
        End Try

        Dim user As String
        user = "xxxxxx@gmail.com"
        Dim data As String = "USER " + user.Trim + vbCrLf
        Dim szData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        Dim POPResponse As String
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("Invalid user Name")
            Return -1
        End If
        Dim password As String
        password = "xxxxxx"
        data = "PASS " & password & vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("Invalid Passwprd")
            Return (-1)
        End If
        data = "STAT" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("could not log your in")
            Return -1
        End If
        data = "Stat" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("could not log your in")
            Return -1
        End If
        Dim parts() As String
        parts = POPResponse.Split(" ")
        Dim messages As Integer, totsize As Integer

        'messages = parts(1)
        messages = CInt(parts(1))
        'messages = parts(1).ToString()
        Return messages
    End Function
Posted
Updated 6-Aug-14 23:41pm
v2
Comments
[no name] 7-Aug-14 6:31am    
The port for pop.gmail.com is 995 not 587
oronsultan 7-Aug-14 6:35am    
when using port 995, the POPResponse is "Nothing".
when using port 587, the POPResponse is "220 mx.google.com ESMTP z5sm8935828wje.49 - gsmtp".
[no name] 7-Aug-14 6:46am    
And so?
oronsultan 7-Aug-14 6:48am    
What is the difference between them?
could you please tell me what am i doing wrong???
[no name] 8-Aug-14 17:26pm    
What do you mean what is the difference? One port is the port for smtp.gmail.com and the other port is for pop.gmail.com. One is correct for what you are doing and the other is not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900