F
François Miermont
Hi there,
I have a problem when trying to import .msg files to outlook : it throws an
error :
"The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))" and make Outlook crash (encountered a problem and needs
to close...). This error doesn't happend on the same MSG File : sometimes, it
appends when it imports about 200 files, sometimes 80...
In fact, I've made a file miror of my Mailboxes : foreach folder in my
mailbox, i make a directory, foreach mail in a folder, I save it as a MSG
File in the directory. This works perfectly without any problem. Let's call
it the Export method.
Now, I try to make the Import method : foreach Directory, I make a folder in
my inbox, foreach MSG File in that directory I make a mail.
I do it recursively using this code :
ApplicationClass myOlApp = new ApplicationClass();
NameSpace newNS = myOlApp.GetNamespace("MAPI");
MAPIFolder mapi1 = newNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
PutMail(myOlApp, mapi1, @"C:\temp\outlook\Inbox");
And this is PutMail :
private void PutMail(ApplicationClass myOlApp, MAPIFolder baseFolder, string
restaurePath)
{
DirectoryInfo root = new DirectoryInfo(restaurePath);
foreach (FileInfo file in root.GetFiles())
{
if (file.Extension == ".msg")
{
MailItem item =
(MailItem)myOlApp.CreateItemFromTemplate(file.FullName, baseFolder);
item = (MailItem)item.Move(baseFolder);
item.Save();
}
}
foreach (DirectoryInfo directory in root.GetDirectories())
{
MAPIFolder myNewFolder = baseFolder.Folders.Add(directory.Name,
OlDefaultFolders.olFolderInbox);
PutMail(myOlApp, myNewFolder, directory.FullName);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myNewFolder);
}
}
I use myOlApp.CreateItemFromTemplate because I didn't find another way to
import a MSG File (except using Redemption but I don't want to).
The error is always throw on this call :
MAPIFolder myNewFolder = baseFolder.Folders.Add(directory.Name,
OlDefaultFolders.olFolderInbox);
Any help will be welcome
I have a problem when trying to import .msg files to outlook : it throws an
error :
"The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))" and make Outlook crash (encountered a problem and needs
to close...). This error doesn't happend on the same MSG File : sometimes, it
appends when it imports about 200 files, sometimes 80...
In fact, I've made a file miror of my Mailboxes : foreach folder in my
mailbox, i make a directory, foreach mail in a folder, I save it as a MSG
File in the directory. This works perfectly without any problem. Let's call
it the Export method.
Now, I try to make the Import method : foreach Directory, I make a folder in
my inbox, foreach MSG File in that directory I make a mail.
I do it recursively using this code :
ApplicationClass myOlApp = new ApplicationClass();
NameSpace newNS = myOlApp.GetNamespace("MAPI");
MAPIFolder mapi1 = newNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
PutMail(myOlApp, mapi1, @"C:\temp\outlook\Inbox");
And this is PutMail :
private void PutMail(ApplicationClass myOlApp, MAPIFolder baseFolder, string
restaurePath)
{
DirectoryInfo root = new DirectoryInfo(restaurePath);
foreach (FileInfo file in root.GetFiles())
{
if (file.Extension == ".msg")
{
MailItem item =
(MailItem)myOlApp.CreateItemFromTemplate(file.FullName, baseFolder);
item = (MailItem)item.Move(baseFolder);
item.Save();
}
}
foreach (DirectoryInfo directory in root.GetDirectories())
{
MAPIFolder myNewFolder = baseFolder.Folders.Add(directory.Name,
OlDefaultFolders.olFolderInbox);
PutMail(myOlApp, myNewFolder, directory.FullName);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myNewFolder);
}
}
I use myOlApp.CreateItemFromTemplate because I didn't find another way to
import a MSG File (except using Redemption but I don't want to).
The error is always throw on this call :
MAPIFolder myNewFolder = baseFolder.Folders.Add(directory.Name,
OlDefaultFolders.olFolderInbox);
Any help will be welcome