我正在使用 Visual Basic 2010 专业版,我正在开发一个软件,其中一部分是获取 [Inbox] 电子邮件,但我什至无法从服务器获得响应。
我做了这些步骤:
- 确保我的 Gmail.com 帐户正在使用 IMAP
- 我使用的是两步验证方法,所以我使用的是我的应用程序密码。
我正在使用这段代码:
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
当我将此登录功能与 [button] 一起使用时:
ListBox1.Items.Clear()
StatResp = Login(m_sslStream, "LOGIN " + UsrNm + " " + PassStr + " ") & vbCrLf
ListBox1.Items.Add(StatResp)
我在 [ListBox] 控件中一无所获。