IMAP 获取响应问题
我正在使用 IMAP,阅读邮件内容时我收到了两次或三次相同的邮件内容。
我检查了不同的不同场景,所以我知道 Response() 给了我重复性 内容。
我像这样传递命令。
byte[] commandBytes = System.Text.Encoding.ASCII.GetBytes(("$ UID FETCH " + index + " (BODY[HEADER.FIELDS (SUBJECT FROM DATE)])" + "\r\n").ToCharArray());
_imapNs.Write(commandBytes, 0, commandBytes.Length);
_imapNs.Flush();
string strMsg = Response();
我的 Stream 和 TcpClient 成员是。
private TcpClient _imapClient;
private Stream _imapNs;
我的响应方法在这里。
private string Response()
{
byte[] data = new byte[_imapClient.ReceiveBufferSize];
int ret = _imapNs.Read(data, 0, data.Length);
return Encoding.ASCII.GetString(data);
}
一旦我检查了这个完整的周期,我就知道 Response() 方法给了我重复的内容,所以有没有解决方案......
谢谢......!!
Iam working on IMAP, reading mail content I got twice or third times of same mails content.
I had check out different different scenario so I comes to know Response() was gives me repeatitive
content.
I am passing Command like this.
byte[] commandBytes = System.Text.Encoding.ASCII.GetBytes(("$ UID FETCH " + index + " (BODY[HEADER.FIELDS (SUBJECT FROM DATE)])" + "\r\n").ToCharArray());
_imapNs.Write(commandBytes, 0, commandBytes.Length);
_imapNs.Flush();
string strMsg = Response();
my member of Stream and TcpClient is.
private TcpClient _imapClient;
private Stream _imapNs;
and my Response method is here.
private string Response()
{
byte[] data = new byte[_imapClient.ReceiveBufferSize];
int ret = _imapNs.Read(data, 0, data.Length);
return Encoding.ASCII.GetString(data);
}
once I had check this complete cycle then I comes to knows the Response() method gives me repeatitive content so is there any solution for that.....
Thanks...!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的代码不可能工作。
您假设服务器响应小于 _imapClient.ReceiveBufferSize。为什么?
服务器响应可能有 50 MB 长。您无法通过对 Stream.Read 方法的单次调用来读取它。
There is no way your code will work.
You have assumed that the server response is smaller than _imapClient.ReceiveBufferSize. Why?
Server response may be 50 MB long. There is no way you'll be able to read it with the single call to Stream.Read method.
我建议您使用可用于 C# 的众多库之一(由于示例的语法,我假设您正在使用该库 - 您没有指定)。
查看现有的 StackOverflow 问题。
在 C# 中访问 IMAP
使用 C# .NET 库检查来自 GMail 服务器的 IMAP 邮件
I would recommend that you use one of the many libraries available for C# (I'm assuming that's what you're using due to the syntax of your example - you didn't specify).
Take a look at the existing StackOverflow questions.
Accessing IMAP in C#
Using C# .NET librarires to check for IMAP messages from GMail servers
我得到了解决方案,因为我想做循环内的所有事情,并且我正在循环外做所有的事情谢谢..!!
I got the Solution, because I want to do all the thing inside the loop and I am doing all the thins outside the loop Thanks..!!