Imap获取命令

时间:2014-07-04 12:00:50

标签: c# imap

我正在使用以下C#代码检索邮件的标题,但我想修改它以便它可以告诉我邮件是否包含任何附件,但是我不想加载带附件的完整邮件

var command = string.Format("FETCH {0} (FLAGS UID BODY[HEADER])", i);
Clean();
SendCommand(command);
var sizeLine = ReadLine();

我已尝试过以下

这会检索完整的消息或者根本不工作,我也在rfc网站上工作,但似乎找不到它的命令

var command = string.Format("FETCH {0} (FLAGS UID BODY.PEEK[])", i);
var command = string.Format("FETCH {0} (FLAGS UID BODY[])", i);
var command = string.Format("FETCH {0} (FLAGS UID BODY[HEADER,MIME])", i);
var command = string.Format("FETCH {0} (FLAGS UID BODY[MIME])", i);

2 个答案:

答案 0 :(得分:3)

您正在寻找的命令是UID FETCH ... BODYSTRUCTURE。一旦看到响应,您可能希望考虑使用库来为您进行解析。在C#,MailKit和IIRC,mailsystem.net上至少有两个候选人。首先尝试mailkit。

答案 1 :(得分:0)

也许您忘了在FETCH命令之前放置UID:

string tag = GetTag();
string response = SendCommandGetResponse(tag + "UID FETCH " + uid + " (BODY" +
                    (seen ? null : ".PEEK") + "[HEADER])", false);

来自S22 ImapClient.cs