我尝试使用find过滤邮件项目,它适用于收件箱项目,但在发送的项目中,它使用过滤器找不到项目。
private void GetNewSyncSentMail()
{
Outlook.MAPIFolder mailSentFolder = null;
Outlook.Items mailItemsSent = null;
Outlook.MailItem mailItemSent = null;
try
{
mailSentFolder = Globals.objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Debug.DebugMessage(3, "Get folder "+mailSentFolder.Name );
mailItemsSent = mailSentFolder.Items;
Debug.DebugMessage(3, "Get sent items " + mailItemsSent.Count);
mailItemSent = mailItemsSent.Find(filter) as Outlook.MailItem;
while (mailItemSent != null)
{
try
{
//Do something
}
catch (Exception exInner)
{
Debug.DebugMessage(2, "Error GetNewSyncSentMail" + exInner.Message);
}
finally
{
if (mailItemSent != null) Marshal.ReleaseComObject(mailItemSent);
mailItemSent = mailItemsSent.FindNext() as Outlook.MailItem;
}
}
}
catch (Exception ex)
{
Debug.DebugMessage(2, "Error in GetNewSyncWSinoSentMail" + ex.Message);
}
finally
{
if (mailItemsSent != null) Marshal.ReleaseComObject(mailItemsSent);
if (mailSentFolder != null) Marshal.ReleaseComObject(mailSentFolder);
}
}
发送的项目满足outlook中的过滤器。但是在上面的代码中找不到。
这是过滤器
public static string syncW = (char)34 + "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/syncW" + (char)34;
public static string sID = (char)34 + "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/sID" + (char)34;
public string filter = "@SQL=((" + syncWi + " = 'True') AND ((" + sID + " = '') OR (" + sID + " IS NULL)))";