我正在尝试从收件箱中删除邮件。消息没有 messageId (它不是gmail)
我在本主题中找到了解决方案
MailSystem.Net Delete Message, IndexOnServer Property = 0
但它对我不起作用。
下面的代码简化了应用程序作为MVVM轻量级应用程序。
这是我收到电子邮件的方式。
for (int i = 1; i <= mails.MessageCount; ++i)
{
Message msg = fetch.MessageObject(i);
MessageModel tmpMsg = new MessageModel() { messageType = MessageModel.MessageType.INBOX, UID = i, Date = msg.Date, Body = content, Title = msg.Subject, Sender = msg.From.Merged, Receiver = msg.To[0].Merged, IsEncrypted = isEncrypted };
tmpMsg.MessageWasDeleted += tmpMsg_MessageWasDeleted;
InboxMessages.Messages.Add(tmpMsg); //this is observable collection of MessageModel
}
我已经测试了这段代码,并将正确的id添加到messageModel对象中。
现在,当我想要删除消息时,我在模型中使用此代码:
var imapClient = new Imap4Client();
imapClient.BeginConnect(ConfigurationManager.AppSettings["mail_smtp_host"], ConfigurationManager.AppSettings["mail_smtp_login"], ConfigurationManager.AppSettings["mail_smtp_password"], new AsyncCallback((res) =>
{
imapClient.EndConnect(res);
//var box = imapClient.AllMailboxes["INBOX"] ;
var box = imapClient.SelectMailbox("INBOX");
Message email = box.Fetch.MessageObject(UID); //this is just to check if proper message is going to be deleted
box.UidDeleteMessage(UID, true);
if (MessageWasDeleted != null) MessageWasDeleted(this, new EventArgs());
}));
此方法根据UID删除邮件(至少它应该这样做),但它没有。没有任何错误出现。
哪里可以出错?使用ActiveUpMail删除邮件的正确方法是什么?