我一直在开发一个小型的控制台应用程序,用于读取邮箱。它工作得很好,但是当它完成邮件的阅读后,我希望将它们移动到“已删除”邮件夹中。我找到了其他相关问题,但似乎没有解决它。我没有收到任何错误消息,而且“已读”标志也非常流畅。如果有问题,请随时评论。
DateTimeOffset test = DateTime.Now;
using (var client = new ImapClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("Imap.outlook.com", 993, true);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("Email@mail.com", "password");
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadWrite);
Console.WriteLine("Total messages: {0}", inbox.Count);
Console.WriteLine("Recent messages: {0}", inbox.Recent);
for (int i = 0; i < inbox.Count; i++)
{
var message = inbox.GetMessage(i);
Console.OutputEncoding = System.Text.Encoding.ASCII;
test = message.Date;
inbox.AddFlags(i , MessageFlags.Seen, true);
inbox.AddFlags(i, MessageFlags.Deleted, true); // Doesn't do anything.
Console.WriteLine("Emne: {0}", message.Subject);
Console.WriteLine("Fra: {0}", message.From);
Console.WriteLine("id: {0}", test);
Console.WriteLine(" ");
}
Console.ReadLine();
client.Disconnect(true);
}