I’m using Visual Basic 2010 professional edition and I’m working on a software that part of it is to get the [Inbox] E-mails, but I can not even get a response from the server.
I did these steps:
- Made sure that my Gmail.com account is working with IMAP
- I’m using 2-step verification method, so I’m using my application password.
-
I’m using this code :
Imports System.Net.Sockets Imports System.IO Imports System.Text Imports System.Net.Security Public Class ImapClient1 Dim ServerNm As String Dim UsrNm As String Dim PassStr As String Dim _IntPort As Integer Dim ImapClient As New Net.Sockets.TcpClient Dim NetworkS_stream As NetworkStream Dim m_sslStream As SslStream Dim Read_Stream As StreamReader Dim StatResp As String Function Login(ByVal Sstream As SslStream, ByVal Server_Command As String) ImapClient = New TcpClient(ServerNm, _IntPort) NetworkS_stream = ImapClient.GetStream 'Read the stream Sstream = New SslStream(NetworkS_stream) Dim Read_Stream2 = New StreamReader(Sstream) Server_Command = Server_Command ' + vbCrLf m_buffer = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray()) Sstream.Write(m_buffer, 0, m_buffer.Length) Dim Server_Reponse As String Server_Reponse = Read_Stream2.ReadLine() Return Server_Reponse End Function
When i use this Login function with a [button] like :
ListBox1.Items.Clear()
StatResp = Login(m_sslStream, "LOGIN " + UsrNm + " " + PassStr + " ") & vbCrLf
ListBox1.Items.Add(StatResp)
I get nothing in the [ListBox] control.
Every IMAP command needs to have a “Tag” prefixed in front of it, which is a random alphanumeric string you need to generate. Typically a login process looks like this: