Dear Support,
Why no one reply to my question, is not supported by the current class i am using to get unread messages??
Hi Bassam,
Try
Console.WriteLine(“Loading PST file…”)
’ load the Outlook PST file
Dim pst As PersonalStorage = PersonalStorage.FromFile(“Sample.pst”)
’ get the Display Name of the PST file
Console.WriteLine("Display Name: " + pst.DisplayName)
’ get the folders and messages information
Dim folderInfo As FolderInfo = pst.RootFolder
’ call the recursive method to display the folder contents
DisplayFolderContents(folderInfo, pst)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub DisplayFolderContents(ByVal folderInfo As FolderInfo, ByVal pst As PersonalStorage)
If folderInfo.DisplayName = “Inbox” Then
’ display the folder name
Console.WriteLine(“Folder: " & Convert.ToString(folderInfo.DisplayName))
Console.WriteLine(“Unread count = " & Convert.ToString(folderInfo.ContentUnreadCount))
Console.WriteLine(”==================================”)
’ display information about messages inside this folder
Dim messageInfoCollection As MessageInfoCollection = folderInfo.GetContents()
For Each messageInfo As MessageInfo In messageInfoCollection
Dim mapi As MapiMessage = pst.ExtractMessage(messageInfo)
Dim isread As Boolean = (mapi.Flags And MapiMessageFlags.MSGFLAG_READ) = MapiMessageFlags.MSGFLAG_READ
If Not isread Then
Console.WriteLine("Subject: " + messageInfo.Subject)
Console.WriteLine(“Sender: " + messageInfo.SenderRepresentativeName)
Console.WriteLine(“Recipients: " + messageInfo.DisplayTo)
Console.WriteLine(”------------------------------”)
End If
Next
End If
’ call this method recursively for each subfolder
If folderInfo.HasSubFolders = True Then
For Each subfolderInfo As FolderInfo In folderInfo.GetSubFolders()
DisplayFolderContents(subfolderInfo, pst)
Next
End If
End Sub
Thank you very much for reply.
Hi Bassam,
Hi Bassam,
FolderInfo inbox = pst.RootFolder.GetSubFolder(“Inbox”);
MessageInfoCollection messages = inbox.GetContents(10, 100);
{
PersonalStorage pst = PersonalStorage.FromFile("TestInbox.pst", true);
FolderInfo infoInbox = pst.GetPredefinedFolder(StandardIpmFolder.Inbox);
MessageInfoCollection messageInfoCollection = infoInbox.GetContents(10,100);
foreach (MessageInfo messageInfo in messageInfoCollection)
{
MapiMessage mapi = pst.ExtractMessage(messageInfo);
bool isread = (mapi.Flags & MapiMessageFlags.MSGFLAG_READ) == MapiMessageFlags.MSGFLAG_READ;
if (!isread)
{
infoInbox.DeleteChildItem(messageInfo.EntryId);
mapi.SetMessageFlags(MapiMessageFlags.MSGFLAG_READ);
infoInbox.AddMessage(mapi);
}
}
}
Hi Mr. Dashif,
Hi Bassam,
- Create a PST
- Create folders Inbox and TestFolder
- Add 100 unread messages to the Inbox folder
- Open the PST
- Select Inbox folder
- Read messages from 10 to 100 index (just to demonstrate selection of messages)
- Delete message from inbox
- Mark it is as Read
- Save the message in a temporary list
- Perform above steps (4 to 6) for all the messages
static void Main(string[] args)
{
var license3 = new Aspose.Email.License();
license3.SetLicense(“Aspose.Email.lic”);
AddMessageToInbox();
UpdatePstMessages();
Console.WriteLine(“Press any key to continue…”);
Console.ReadKey();
}
static private void AddMessagsToInbox()
{
if (File.Exists(@“TestInbox.pst”))
{
File.Delete(@“TestInbox.pst”);
}
PersonalStorage pst = PersonalStorage.Create(“TestInbox.pst”, FileFormatVersion.Unicode);
pst.CreatePredefinedFolder(“Inbox”, StandardIpmFolder.Inbox);
pst.RootFolder.AddSubFolder(“TestFolder”);
MapiMessage msg = new MapiMessage("newcustomeronnet@gmail.com", "newcustomeronnet1@gmail.com", “Test Subject”, “Test Body”);
FolderInfo infoInbox = pst.GetPredefinedFolder(StandardIpmFolder.Inbox);
for (int iCount = 0; iCount <= 100; iCount++)
{
msg.Subject = “Test Subject-” + iCount;
msg.SetBodyContent(“Test Body-” + iCount, BodyContentType.PlainText);
msg.SetMessageFlags(~MapiMessageFlags.MSGFLAG_READ);
infoInbox.AddMessage(msg);
}
}
static private void UpdatePstMessages()
{
PersonalStorage pst = PersonalStorage.FromFile(“TestInbox.pst”, true);
FolderInfo infoInbox = pst.GetPredefinedFolder(StandardIpmFolder.Inbox);
FolderInfo infoTestFolder = pst.RootFolder.GetSubFolder(“TestFolder”);
List mapiMsgs = new List();
MessageInfoCollection messageInfoCollection = infoInbox.GetContents(10,100);
foreach (MessageInfo messageInfo in messageInfoCollection)
{
MapiMessage mapi = pst.ExtractMessage(messageInfo);
bool isread = (mapi.Flags & MapiMessageFlags.MSGFLAG_READ) == MapiMessageFlags.MSGFLAG_READ;
if (!isread)
{
infoInbox.DeleteChildItem(messageInfo.EntryId);
mapi.SetMessageFlags(MapiMessageFlags.MSGFLAG_READ);
mapiMsgs.Add(mapi);
}
}
pst.Dispose();
pst = PersonalStorage.FromFile(“TestInbox.pst”, true);
infoTestFolder = pst.RootFolder.GetSubFolder(“TestFolder”);
foreach (MapiMessage mapiMsg in mapiMsgs)
{
infoTestFolder.AddMessage(mapiMsg);
}
}
Yes. It works now perfect.
Hi Bassam,
The issues you have found earlier (filed as NETWORKNET-33388) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.