MS Office Forum / Outlook / Programming VBA / March 2006
RPC_E_SERVERFAULT error when trying to import mail
|
|
Thread rating:  |
François Miermont - 27 Feb 2006 17:34 GMT 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 :)
François Miermont - 27 Feb 2006 17:41 GMT I'm sorry I have forgotten some details : -Office 2003 SP2 -Windows XP SP2
> Hi there, > [quoted text clipped - 53 lines] > > Any help will be welcome :) Eric Legault [MVP - Outlook] - 27 Feb 2006 19:30 GMT The CreateItemFromTemplate method is ONLY to be used with .oft files, not .msg files. I recommend you stick with Redemption.
 Signature Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/
> Hi there, > [quoted text clipped - 53 lines] > > Any help will be welcome :) Sue Mosher [MVP-Outlook] - 27 Feb 2006 20:04 GMT Why do you say that, Eric? There are scenarios where CreateItemFromTemplate can be useful with a .msg file -- say if you want to get at the attachments in a message that was itself an attachment to another message.
What looks to me like a problem in Franois' code is that he's creating the message in a folder, then moving the message to that same folder then saving it. But of course there's nothing to save because the item was moved (and messages don't like to be created in folders; they're always in Drafts). I'd try using System.Missing as the 2nd parameter in CreateItemFromTemplate.
Also if he's adding a folder to an existing mail folder's Folders collection, he could try specifying System.Missing instead of OlDefaultFolders.olFolderInbox.
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> The CreateItemFromTemplate method is ONLY to be used with .oft files, not > .msg files. I recommend you stick with Redemption. [quoted text clipped - 56 lines] >> >> Any help will be welcome :) Eric Legault [MVP - Outlook] - 27 Feb 2006 22:28 GMT Ya lost me Sue! I thought you can only pass the path to an .oft file as the argument to the CreateItemFromTemplate method?? Isn't he trying to import an .msg file into a MAPIFolder? In that case, wouldn't the CopyFile method be apprpriate? But doesn't that create a DocumentItem object from an .msg file, not the Mailitem object you'd expect?
 Signature Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/
> Why do you say that, Eric? There are scenarios where CreateItemFromTemplate can be useful with a .msg file -- say if you want to get at the attachments in a message that was itself an attachment to another message. > [quoted text clipped - 61 lines] > >> > >> Any help will be welcome :) Sue Mosher [MVP-Outlook] - 27 Feb 2006 22:35 GMT CreateItemFromTemplate *does* work with .msg files. It just doesn't necessarily do what people expect, because it does what the method describes -- creates a new item using the .msg file as a template. That means it's no good for importing messages.
The only import technique I know that works is Redemption's.
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> Ya lost me Sue! I thought you can only pass the path to an .oft file as the > argument to the CreateItemFromTemplate method?? Isn't he trying to import an [quoted text clipped - 68 lines] >> >> >> >> Any help will be welcome :) François Miermont - 28 Feb 2006 09:16 GMT Okay now it works perfectly using System.Reflexion.Missing.Value in CreateItemFromTemplate and Folders.Add.
But now it works, I see that it did not do what I expect : the process really restore my mails in correct folders, but these mails are not marked as sent. Exemple : I received a mail from thomas, my friend. I can open it, and then choose Reply. I export this mail, delete it in Outlook, and then restore it. Now, in this mail I can read "This message has not been sent". If I open it, I haven't access to the Reply button : instead of I only have Send.
Sue you says that CreateItemFromTemplate is not the correct method to import msg file, as it not import the mail, but create a new item from this mail. But what can I do if I don't want to use Redemption ? In fact, I just want to do the same behaviour as if I drag&drop a MSG file into Outlook.
> CreateItemFromTemplate *does* work with .msg files. It just doesn't necessarily do what people expect, because it does what the method describes -- creates a new item using the .msg file as a template. That means it's no good for importing messages. > [quoted text clipped - 71 lines] > >> >> > >> >> Any help will be welcome :) Sue Mosher [MVP-Outlook] - 28 Feb 2006 13:15 GMT The Outlook object model provides no way to do that programmatically. You have to go to either Extended MAPI or Redemption.
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
"Franois Miermont" <fmiermont[at]netfinances.fr> wrote in message news:172E2B7D-346B-4F41-81A8-FA515E4A0FF1@microsoft.com...
> > Sue you says that CreateItemFromTemplate is not the correct method to import > msg file, as it not import the mail, but create a new item from this mail. > But what can I do if I don't want to use Redemption ? In fact, I just want to > do the same behaviour as if I drag&drop a MSG file into Outlook. François Miermont - 28 Feb 2006 14:10 GMT I dont have any idea of how using ExMapi with .net. If you have any links :)
> The Outlook object model provides no way to do that programmatically. You have to go to either Extended MAPI or Redemption. > > > Sue you says that CreateItemFromTemplate is not the correct method to import > > msg file, as it not import the mail, but create a new item from this mail. > > But what can I do if I don't want to use Redemption ? In fact, I just want to > > do the same behaviour as if I drag&drop a MSG file into Outlook. Sue Mosher [MVP-Outlook] - 28 Feb 2006 14:36 GMT Extended MAPI is not supported in .NET. You'd have to go to a third-party wrapper there, too -- http://www.mapi33.adexsolutions.com/
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
"Franois Miermont" <fmiermont[at]netfinances.fr> wrote in message news:1D31F51D-082A-45E5-867E-ED39082C0F40@microsoft.com...
>I dont have any idea of how using ExMapi with .net. If you have any links :) > [quoted text clipped - 6 lines] >> > But what can I do if I don't want to use Redemption ? In fact, I just want to >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Francois Miermont - 28 Feb 2006 14:56 GMT Sweet, this is a non-free wrapper that cost the same as Redemption.
So there is no way to import an msg file in outlook in .net expect using redemption ? I can't understand that !
> Extended MAPI is not supported in .NET. You'd have to go to a third-party wrapper there, too -- http://www.mapi33.adexsolutions.com/ > [quoted text clipped - 6 lines] > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Francois Miermont - 28 Feb 2006 15:36 GMT Okay I just try to use Redemption to see what I can do with it. So I'll try to import my msg file.
On the Redemption website, I'm unable to find a way to import a msg file without creating a new item in Outlook. The given code is like this : dim sItem, oItem set sItem = CreateObject("Redemption.SafeMailItem") set oItem = Application.Session.GetDefaultFolder(16).Items.Add(6) sItem.Item = oItem sItem.Import "c:\temp\test.msg", 3 'olMSG, olRFC822 and olTNEF formats are supported sItem.Save
In fact, it the same behaviour as an ImportFromTemplate call : the imported mail is a new item, so I haven't the Reply button.
Or maybe I'm not doing it correctly ?
> Sweet, this is a non-free wrapper that cost the same as Redemption. > [quoted text clipped - 11 lines] > > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to > > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Sue Mosher [MVP-Outlook] - 28 Feb 2006 15:48 GMT Take a look at the sample at http://www.outlookcode.com/codedetail.aspx?id=716, which has worked fine for me. You need to set the MessageClass to "IPM.Note" after you perform the import.
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> Okay I just try to use Redemption to see what I can do with it. So I'll try > to import my msg file. [quoted text clipped - 32 lines] >> > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to >> > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Francois Miermont - 28 Feb 2006 16:16 GMT It seems that I don"t have this MessageClass propertie avaible in my SafeMailItem Class ?
> Take a look at the sample at http://www.outlookcode.com/codedetail.aspx?id=716, which has worked fine for me. You need to set the MessageClass to "IPM.Note" after you perform the import. > [quoted text clipped - 31 lines] > >> > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to > >> > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Sue Mosher [MVP-Outlook] - 28 Feb 2006 16:21 GMT Redemption will pass the MessageClass through to the SafeMailItem.Item, but C# doesn't know that, and I don't do that language, so I don't know how you're supposed to code it. You could try SafeMailItem.Save, followed by setting SafeMailItem.Item.MessageClass and then SafeMailItem.Item.Save
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> It seems that I don"t have this MessageClass propertie avaible in my > SafeMailItem Class ? [quoted text clipped - 37 lines] >> >> > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to >> >> > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Francois Miermont - 28 Feb 2006 16:35 GMT Just try it and does not work :/
Is there a way to ask Redemption's author directly ?
> Redemption will pass the MessageClass through to the SafeMailItem.Item, but C# doesn't know that, and I don't do that language, so I don't know how you're supposed to code it. You could try SafeMailItem.Save, followed by setting SafeMailItem.Item.MessageClass and then SafeMailItem.Item.Save > [quoted text clipped - 36 lines] > >> >> > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to > >> >> > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Francois Miermont - 28 Feb 2006 16:46 GMT Interresting, I've just tested to trace the content of MessageClass : when the message is imported, MessageClass = "IPM.Note" when it's saved, MessageClass = "IPM.Note"
Furthermore, when locking the documention about MailItem, MessageClass is a get/set attribute ! So, I have tested setting MessageClass in my method using CreateFromTemplate. The set seems to work, but unfortunately it does not solve my problem, as it's already set as "IPM.Note"
Maybe MessageClass is not the solution ?
> Just try it and does not work :/ > [quoted text clipped - 40 lines] > > >> >> > >> > But what can I do if I don't want to use Redemption ? In fact, I just want to > > >> >> > >> > do the same behaviour as if I drag&drop a MSG file into Outlook. Dmitry Streblechenko - 28 Feb 2006 19:06 GMT Here I am :-) SafeMailItem object in Redemption only exposes properties and methods blocked by the Outlook Object Model. MessageClass is not blocked, hence SafeMailItem does not implement it. You can either set that property on the original Outlook object assigned to the SafeMailItem.Item property or use RDOMail object (no Outlook objects involed) - http://www.dimastr.com/redemption/rdo/. RDOMail object has a Sent property, which is, unlike OOM, r/w, but you will get an error if you set it after the message was saved at least once (just a MAPI limitation). This way you don't even need to mess with the MessageClass - just call Import(), then set the Sent property ot true.
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Just try it and does not work :/ > [quoted text clipped - 68 lines] >> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into >> >> >> > >> > Outlook. Sue Mosher [MVP-Outlook] - 28 Feb 2006 22:02 GMT Sounds like I need to update my sample for Redemption 4.0, huh?
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx
> Here I am :-) > SafeMailItem object in Redemption only exposes properties and methods [quoted text clipped - 85 lines] >>> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into >>> >> >> > >> > Outlook. Francois Miermont - 01 Mar 2006 11:07 GMT Hello Dmitry :)
I have tested RDOMail object, and putting the Sent propertie to true, and I works ! Furthermore, I have incredible performance, less than one minute to restore a 150MB mailbox !
Just a little question : the unread flag seems to not be restored despite it is really saved. What can I do to solve this minor problem ?
> Here I am :-) > SafeMailItem object in Redemption only exposes properties and methods [quoted text clipped - 85 lines] > >> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into > >> >> >> > >> > Outlook. Francois Miermont - 01 Mar 2006 14:17 GMT Another question (I know I'm too curious). When I restore a 57MB mailboxe, it become a 47MB mailboxe.
For exemple, I have an original mail at 13KB, then restored at 7KB. I use OutlookSpy (great tool !) to see the difference between them, and found : PR_CHANGE_KEY PR_CREATION_TIME PR_ENTRYID PR_LAST_MODIFICATION_TIME PR_PARENT_ENTRYID PR_PREDECESSOR_CHANGE_LIST PR_RECORD_KEY PR_RTF_IN_SYNC PR_SEARCH_KEY
For those I think it's normal but : PR_RTF_COMPRESSED (Original mail : MAPI_E_NOT_FOUND, restored mail : a huge value) PR_MESSAGE_SIZE (Original : 13517, restored 6732)
So as we can see, the Size attribute is not the same, which reflect the difference. The PR_RTF_COMPRESSED attribute is the one which interrest me : is that mean that Redemption can compressed mail when importing it ?? That will be the explication of the differents sizes ? I want to be sure that I'm not loosing data when I'm backup/restore.
> Hello Dmitry :) > [quoted text clipped - 94 lines] > > >> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into > > >> >> >> > >> > Outlook. Dmitry Streblechenko - 01 Mar 2006 18:54 GMT Are you importing MSG files or EML?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Hello Dmitry :) > [quoted text clipped - 116 lines] >> >> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into >> >> >> >> > >> > Outlook. Francois Miermont - 02 Mar 2006 09:06 GMT That's msg file. And when I drap & drop the msg file onto outlook, it is flagged as non-read.
> Are you importing MSG files or EML? > [quoted text clipped - 123 lines] > >> >> >> >> > >> > do the same behaviour as if I drag&drop a MSG file into > >> >> >> >> > >> > Outlook. Dmitry Streblechenko - 02 Mar 2006 17:54 GMT Yes, Redemption skips the PR_MESSAGE_FLAGS property (where MSGFLAG_READ bit is stored) when saving MSG files. Send an e-mail to my private address and I'll send you a beta version with a fix.
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> That's msg file. And when I drap & drop the msg file onto outlook, it is > flagged as non-read. [quoted text clipped - 145 lines] >> >> >> >> >> > >> > into >> >> >> >> >> > >> > Outlook.
|
|
|