ksor
Active member
- Joined
- Jul 4, 2019
- Messages
- 33
- Programming Experience
- 10+
Just some background: Outlook is my local client for a GMAIL with 2 step logon and it's been working for years with some problems now and then.
The last days Outlook (which I has running all day) came up with the logon dialog as if it wants me to enter my password again !!!
When I set it up back then I used a 4 X 4 letter sequence generated by Google and I've ALLWAYS had problem find WHERE this generator was to find - the link I stored was pointing to something else when I should use the 4X4code again !
This time I could NOT find it so after some time I was forced to take a backup of my Outlook datafile and the re-install Outlook.
I managed to re-install Outlook and get it working again, BUT was NOT aware of the install is now IMAP format where my old Outlook was POP, so my backup was NOT useable !
I now wants to extract 1) folder with emails from my old INBOX and 2) my contacts - calender I just reconstruct in the new Outlook.
I'm using Microsoft Visual Studio Community 2022 (64-bit)and I found this C# code out there and changed the path to the PST-file to fit my needs:
IThe code runs til line 19 and then an exception comes up saying: An object was not found (tranlated from DANISH !)
What am I doing wrong ?
The last days Outlook (which I has running all day) came up with the logon dialog as if it wants me to enter my password again !!!
When I set it up back then I used a 4 X 4 letter sequence generated by Google and I've ALLWAYS had problem find WHERE this generator was to find - the link I stored was pointing to something else when I should use the 4X4code again !
This time I could NOT find it so after some time I was forced to take a backup of my Outlook datafile and the re-install Outlook.
I managed to re-install Outlook and get it working again, BUT was NOT aware of the install is now IMAP format where my old Outlook was POP, so my backup was NOT useable !
I now wants to extract 1) folder with emails from my old INBOX and 2) my contacts - calender I just reconstruct in the new Outlook.
I'm using Microsoft Visual Studio Community 2022 (64-bit)and I found this C# code out there and changed the path to the PST-file to fit my needs:
C#:
using Microsoft.Office.Interop.Outlook;
using System;
using System.Activities;
namespace KS_Read_PST_1
{
internal class Program {
static void Main(string[] args) {
Activity workflow1 = new Workflow1();
WorkflowInvoker.Invoke(workflow1);
string pstFilePath = @"C:\Users\kelds\POPkeld.soerensenS@gmail.com.pst";
Application app = new Application();
NameSpace outlookNs = app.GetNamespace("MAPI");
// Add PST file (Outlook Data File) to Default Profile
outlookNs.AddStore(pstFilePath);
MAPIFolder rootFolder = outlookNs.Stores["items"].GetRootFolder();
// Traverse through all folders in the PST file
// TODO: This is not recursive
Folders subFolders = rootFolder.Folders;
foreach (Folder folder in subFolders) {
Items items = folder.Items;
foreach (object item in items) {
if (item is MailItem) {
// Retrieve the Object into MailItem
MailItem mailItem = item as MailItem;
Console.WriteLine("Saving message {0} ....", mailItem.Subject);
// Save the message to disk in MSG format
// TODO: File name may contain invalid characters [\ / : * ? " < > |]
mailItem.SaveAs(@"C:\Users\kelds\EXT\" + mailItem.Subject + ".msg", OlSaveAsType.olMSG);
}
}
}
// Remove PST file from Default Profile
outlookNs.RemoveStore(rootFolder);
}
}
}
IThe code runs til line 19 and then an exception comes up saying: An object was not found (tranlated from DANISH !)
What am I doing wrong ?