【发布时间】:2018-02-21 07:18:44
【问题描述】:
我正在尝试将所有电子邮件移动到 Outlook 中另一个文件夹中,主题为:
“消息传递失败”
每次foreach 循环运行时,最后一封电子邮件总是留在收件箱中并且循环中断。
OutLook.MAPIFolder inBox = mOulook.Application.ActiveExplorer().Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox);
OutLook.Items inBoxItems = inBox.Items;
OutLook.MailItem newEmail = null;
//Creating destination folder where emails are going to be moved
Microsoft.Office.Interop.Outlook.MAPIFolder destFolder = null;
if (destFolder == null)
{
destFolder = inBox.Folders["Test"];
}
//moving each email from source to destination
foreach (object eMail in inBoxItems)
{
try
{
newEmail = eMail as Microsoft.Office.Interop.Outlook.MailItem;
if (newEmail != null)
{
string titleSubject = (string)newEmail.Subject;
if (titleSubject == "Message Delivery Failure")
{
newEmail.Move(destFolder);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
【问题讨论】:
-
请注意,它不存在任何
asp.net win forms。你这里说的是winforms,asp.net是另一个世界
标签: c# winforms visual-studio outlook