Outlook: Recovering e-mail messages from attachments
Recently, I was what I thought to be dragging e-mail from my Inbox into my Personal Folders. Outlook warned me that the process could take some time due to the amount of messages selected, but I went ahead with the move. After a while, Outlook popped up a freshly created e-mail message containing my 1000+ e-mail messages!
The new e-mail was about 85MB and the original message were gone from my inbox... I really wanted those e-mails in my Personal Folders. However, Outlook programming is something I've always shied away from. After some experimenting, I discovered what I wanted couldn't be easily done using Outlook APIs...
I wanted to:
This code misses all kinds of nice sanity checks, like whether the attachment actually is a MSG file, etc. It sufficed for my scenario and I now have the e-mails back. FYI :-D
The new e-mail was about 85MB and the original message were gone from my inbox... I really wanted those e-mails in my Personal Folders. However, Outlook programming is something I've always shied away from. After some experimenting, I discovered what I wanted couldn't be easily done using Outlook APIs...
I wanted to:
- Open the e-mail message containing the attached 1000+ 'backups'
- Iterate the attachments
- Save the attachments as e-mails into my Personal Folders box
// To use this namespace you must set a
// reference to the Microsoft Outlook 11.0
// COM server.
using Microsoft.Office.Interop.Outlook;
using OutLookApp = Microsoft.Office.Interop.Outlook.Application;
using System.IO;
using rd = Redemption;
ApplicationClass outLookApp = new ApplicationClass();
NameSpace outlookNS = outlookApp.GetNamespace("MAPI");
MailItem attachmentsItem = (MailItem)outlookNS.GetItemFromID(messageId, null);
// left out for clarity: find the Personal Folders->Inbox folder
rd.MAPIUtils utils = new rd.MAPIUtils();
utils.MAPIOBJECT = outlookNS.MAPIOBJECT;
foreach (Attachment a in attachmentsItem.Attachments)
{
string attachmentFile = Path.GetTempFileName();
a.SaveAsFile(attachmentFile);
MailItem underlyingItem =
(MailItem)personalFolder.Items.Add(OlItemType.olMailItem);
rd.MessageItem neww =
utils.GetItemFromMsgFile(attachmentFile, false);
underlyingItem.Save();
MailItem placedItem =
(MailItem)underlyingItem.Move(personalFolder);
neww.CopyTo(placedItem);
}
This code misses all kinds of nice sanity checks, like whether the attachment actually is a MSG file, etc. It sufficed for my scenario and I now have the e-mails back. FYI :-D
7 Comments:
niche post :)
Informasi Seputar Indonesia
My Friendfeed
My Twitter
My ping
By isiweb, at 6:54 AM
EFX bracelet is a new trend of bracelets in French, and it will sweep the whole world in the near future without doubt.
Power balance here provides lot of pictures for you.
Emporio Armani
omega-watch
By Unknown, at 10:12 AM
It's hard to find quality writing like yours these days. I really appreciate people like you! Take care and see you soon
Poster Printing
By Carbonless Forms, at 4:11 PM
Yes, sometime it happens.. Outlook does something than what it supposed to do.. You have shared your experience and discovered the solution for it, and thats great to shared with us. Thanks for sharing the information with us.
By Ecommerce website developer, at 10:53 AM
Great post! I am actually getting ready to go across, this post is very informative. By the way, Get funny mothers day messages
funny mothers day sayings
mothers day sayings
By Unknown, at 11:32 AM
Good work…unique site and interesting too… keep it up…looking forward for more updates.Good luck to all of you and thanks so much for your hard-work.
Transcription Services Bangalore, Voice Over Artist in India
By Unknown, at 12:57 PM
I am very happy when read this blog post because blog post written in good manner and write on good topic.
Thanks for sharing valuable information.
digital marketing company in bangalore,
Digital Marketing Company
By devidnayana, at 7:42 AM
Post a Comment
<< Home