1

I regularly receive forwarded emails that come as Outlook formatted .msg files. These emails were forwarded as attachments from another exchange server. If I drag the attached messages to my Inbox, they show up just like any other email. I would like to find an automated way to extract these attached emails to my inbox and delete the original messaged that contained the .msg file.

I’m sure this can be accomplished through a rule in conjunction with an Outlook VBA, but I lack the skill to write this code from scratch.

Any pointers or sample code to get me started?

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
Joseph
  • 21
  • 2
  • Possible duplicate of [Automatically Unpack Attached Messages](https://stackoverflow.com/questions/19542982/automatically-unpack-attached-messages) – niton Sep 20 '17 at 00:43

1 Answers1

3

Here is how I would do it. However, I will give you pieces of code which you will have to merge together.

Logic:

  1. Extract the attachment and save it to say C:\
  2. Use the method CreateItemFromTemplate() to open the .msg file. More about it HERE
  3. Move the message to the relevant folder

Code for Extracting attachments: Covered HERE

Code for opening the .msg file:

Sub CreateFromTemplate()
    Dim MyItem As Outlook.MailItem

    Set MyItem = Application.CreateItemFromTemplate("C:\Blah Blah.msg")
    MyItem.Display
End Sub

Now you have the handle to the .msg i.e MyItem, simply move it to the relevant folder and then delete the original email

Code for moving to a different folder: Covered HERE. If you search google, you will get more sample codes for this.

Hope this gets you on the right path.

Community
  • 1
  • 1
Siddharth Rout
  • 137,434
  • 15
  • 189
  • 237
  • Thank you very much for this answer, it helped me construct my own code sample that works very well. Unfortunately, when I unpack attached messages via CreateItem the resulting message in the Inbox mentions that it "has not been sent". I'm not sure how to remove this message. I saw a suggestion on saving mails as "Post" items instead, but don't know what these are and if this would solve my problem. Do you have any advice? – Lilienthal Oct 21 '13 at 11:41
  • Can you update your question with the latest code that you are using? – Siddharth Rout Oct 21 '13 at 11:43
  • It's not actually my question though, I stumbled across it while trying to figure this out today. I might create a new question on it with the full code if I can't resolve it, but right now I've encountered issue with Outlook (it's refusing to run scripts at the moment) that I'll have to resolve first. – Lilienthal Oct 21 '13 at 12:23
  • Macros are disabled, I guess? – Siddharth Rout Oct 21 '13 at 12:24
  • That was the first thing I checked, actually the issue was a debug statement outside a Sub in ThisOutlookSession. The program is now working again, though with the issues above. If I can't resolve it I'll submit a new question as this we're probably drifting off topic. – Lilienthal Oct 22 '13 at 12:26
  • Question created at http://stackoverflow.com/questions/19542982/automatically-unpack-attached-messages – Lilienthal Oct 23 '13 at 13:27