如何在VB.net中使用IMAP命令来获取Gmail.com服务器的响应? [英] How can I use IMAP commands in VB.net to get response from Gmail.com server?

查看:109
本文介绍了如何在VB.net中使用IMAP命令来获取Gmail.com服务器的响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Basic 2010专业版,而我正在使用的软件,其中一部分是获取[收件箱]电子邮件,但我甚至不能从服务器得到响应。

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.

我做了这些步骤:


  1. 确保我的Gmail.com帐户正在使用IMAP

  2. 我使用两步验证方法,所以我使用我的应用程序密码。

  3. 我使用这段代码:

  1. Made sure that my Gmail.com account is working with IMAP
  2. I'm using 2-step verification method, so I'm using my application password.
  3. 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)

我没有在[ListBox]控制。

I get nothing in the [ListBox] control.

推荐答案

每个IMAP命令需要在前面加上一个Tag,这是一个随机的字母数字字符串需要生成。通常,登录过程如下所示:

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:

A001 LOGIN user password
A002 SELECT INBOX
A003 ...
...
A010 LOGOUT

这篇关于如何在VB.net中使用IMAP命令来获取Gmail.com服务器的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆