Solved

how to export messages from Outlook to Windows shell in .msg format

Posted on 2008-10-16
16
467 Views
Last Modified: 2012-05-05
Hi,
I want to export e-mail messages from Outlook 2007 to Windows folder. I DON'T want to seprate the attachments, they are fine if they keep on residing inside the message.

It would also be much helpful if it could be made as a Scheduled Task so that user does not have to interact & it becomes an Automatic Process.

I found one Software (http://www.techhit.com/messagesave/) for doing this Activity, however if someone could suggest some code or something with which I can Avoid installing a Third Party software?

Best,
A
0
Comment
Question by:Ackles
  • 9
  • 7
16 Comments
 
LVL 11

Author Comment

by:Ackles
ID: 22739413
What does Neglected Question mean? Why is it Neglected?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22742909
Hi, Ackles.

Neglected question means that an expert hasn't responded within a set amount of time, 12 hours I think.  

I can provide a script that'll do this, I just need a few more details.  What Outlook folder do you want to export from and doyou want to export all messages or only those that meet a certain condition?  Also, what folder do you want to export to?
0
 
LVL 11

Author Comment

by:Ackles
ID: 22745552
Hi,
I basically want to export all the e-mails from Outlook irrespective weather they have attachments or not. I can use a Rule to send Copy of all Incoming & Sent e-mails to a sub-folder or any other folder you want me to have.

My only criteria is that all the messages should be thrown to Windows Shell. If this Script can also Delete the messages after throwing or exporting to Windows Shell then it would be Fabulous as there will be no chance of Duplication. As far as the folder I want to export is concerned it would be more suitable if that can be our Network folder which is a Shared Folder on server.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22746549
The code below exports the current folder and all sub-folders to the file system.  Items are saved in .msg format and the items are deleted from Outlook as they're exported.  You didn't mention exporting to sub-folders, so this version exports all messages to the same file system folder.  Follow these instructions to use this code.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on Module1
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comments wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Select a folder and run the macro.  Selecting a top-level folder (e.g. mailbox or PST file) will export everything in that mailbox or PST file.

Sub RunExportFolder()

    ExportFolder Application.ActiveExplorer.CurrentFolder

End Sub
 

Sub ExportFolder(olkFolder As Outlook.Folder)

    'Change the folder path on the following line.  This is the path to the folder all items will be saved to.'

    Const FOLDER_PATH = "C:\eeTesting\Messages\"

    Dim olkItem As Outlook.MailItem, olkSubfolder As Outlook.Folder, intIndex As Integer

    For intIndex = olkFolder.Items.Count To 1 Step -1

        Set olkItem = olkFolder.Items(intIndex)

        olkItem.SaveAs FOLDER_PATH & ReplaceIllegalCharacters(olkItem.Subject) & ".msg", olMSG

        'olkItem.Delete

    Next

    For Each olkSubfolder In olkFolder.Folders

        ExportFolder olkSubfolder

    Next

    Set olkItem = Nothing

End Sub
 

Function ReplaceIllegalCharacters(strSubject As String) As String

    Dim strBuffer As String

    strBuffer = Replace(strSubject, ":", "")

    strBuffer = Replace(strBuffer, "\", "")

    strBuffer = Replace(strBuffer, "/", "")

    strBuffer = Replace(strBuffer, "?", "")

    strBuffer = Replace(strBuffer, Chr(34), "'")

    strBuffer = Replace(strBuffer, "|", "")

    ReplaceIllegalCharacters = strBuffer

End Function

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 22746552
Oops, hit Submit a little too fast.  Uncomment (i.e. remove the apostrophe) at the beginning of line #12.
0
 
LVL 11

Author Comment

by:Ackles
ID: 22752087
THANKS SO VERY MUCH!!! (Sorry Don't know your Name).

I will Accept this as a Solution to my desired Query after I check it on Monday on my Office Computer as I don't have Windows home, however if I am not being mean, can I request one more Additional thing:

Is it possible to make it as a Scheduled Task like say once in a day so that there is no User Interaction required?

If this can be done, you have saved me a lot of Trouble.

Thanks a lot once again, best regards,
A
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22752275
You're welcome.  My name is David.

No, that's not too much to ask for.  Replace the code with the version below.  Follow these instructions to use it.

1.  Open Notepad
2.  Copy the code and paste it into Notepad
3.  Edit the code per the comments in the code
4.  Save the file with a .vbs extension
5.  Use Windows built-in task scheduler to set this up as an automatic task.  The command line will be something like

    CScript.exe Scriptname.vbs


Const olFolderInbox = 6

Dim olkApp, olkSes, olkRootFolder

On Error Resume Next

Set olkApp = GetObject(,"Outlook.Application")

If Err.Number <> 0 Then

    Set olkApp = CreateObject("Outlook.Application")

    Set olkSes = olkApp.GetNameSpace("MAPI")

    'Change the profile name on the following line as needed'

    olkSes.Logon "Outlook"

End If

'Change the folder path on the following line as needed'

Set olkRootFolder = olkSes.GetDefaultFolder(olFolderInbox)

ExportFolder olkRootFolder

Set olkRootFolder = Nothing

Set olkSes = Nothing

Set olkApp = Nothing

WScript.Quit

 

Sub ExportFolder()

    'Change the folder path on the following line.  This is the path to the folder all items will be saved to.'

    Const FOLDER_PATH = "C:\eeTesting\Messages\"

    Dim olkItem, olkSubfolder, intIndex

    For intIndex = olkFolder.Items.Count To 1 Step -1

        Set olkItem = olkFolder.Items(intIndex)

        olkItem.SaveAs FOLDER_PATH & ReplaceIllegalCharacters(olkItem.Subject) & ".msg", olMSG

        olkItem.Delete

    Next

    For Each olkSubfolder In olkFolder.Folders

        ExportFolder olkSubfolder

    Next

    Set olkItem = Nothing

End Sub

 

Function ReplaceIllegalCharacters(strSubject)

    Dim strBuffer

    strBuffer = Replace(strSubject, ":", "")

    strBuffer = Replace(strBuffer, "\", "")

    strBuffer = Replace(strBuffer, "/", "")

    strBuffer = Replace(strBuffer, "?", "")

    strBuffer = Replace(strBuffer, Chr(34), "'")

    strBuffer = Replace(strBuffer, "|", "")

    ReplaceIllegalCharacters = strBuffer

End Function

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 22752597
David,
I have been never so Eager in my whole life to go to Office as I am today!!!

Will do the First Thing in the Morning & will let you know the Good News.
Kind regards,
A
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 11

Author Comment

by:Ackles
ID: 22757424
David,
I did slight modfification to the code given by you to satisfy  my need, i understood from the code that , the mails from standard folders INBOX , SENT ITEM only can be extracted and archived in windows folder ,is there any way ,we can extract the emails from the customized folder , example <Some Name>.
Please let me know if you have any questions.

Kind Regards
A

Const olFolderInbox = 6
Const FOLDER_PATH = "C:\mess\"
    Dim olkItem, olkSubfolder, intIndex
    Dim olkApp, olkSes, olkRootFolder

On Error Resume Next
Set olkApp = GetObject(, "Outlook.Application")

If Err.Number = 0 Then
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    'Change the profile name on the following line as needed'
    olkSes.Logon "Exchange Server"
End If

'Change the folder path on the following line as needed'

Set olkRootFolder = olkSes.GetDefaultFolder(olFolderInbox)
'Set olkRootFolder = olkSes.GetDefaultFolder(2)
'MsgBox olkRootFolder
ExportFolder olkRootFolder
Set olkRootFolder = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Sub ExportFolder(olkFolder)
    'Change the folder path on the following line.  This is the path to the folder all items will be saved to.'
    Dim a
    a = olkFolder.Items.Count
   ' MsgBox a
    'MsgBox "The count is " & olkFolder.Items.Count
    For intIndex = olkFolder.Items.Count To 1 Step -1
        Set olkItem = olkFolder.Items(intIndex)
        olkItem.SaveAs FOLDER_PATH & ReplaceIllegalCharacters(olkItem.Subject) & ".msg"
        'olkItem.Delete
    Next
    For Each olkSubfolder In olkFolder.Folders
        ExportFolder olkSubfolder
    Next
    Set olkItem = Nothing
End Sub
 
Function ReplaceIllegalCharacters(strSubject)
    Dim strBuffer
    strBuffer = Replace(strSubject, ":", "")
    strBuffer = Replace(strBuffer, "\", "")
    strBuffer = Replace(strBuffer, "/", "")
    strBuffer = Replace(strBuffer, "?", "")
    strBuffer = Replace(strBuffer, Chr(34), "'")
    strBuffer = Replace(strBuffer, "|", "")
    ReplaceIllegalCharacters = strBuffer
End Function

0
 
LVL 76

Expert Comment

by:David Lee
ID: 22759535
Do you want to export one folder at a time or all of the fodlers in a given mailbox or PST file?
0
 
LVL 11

Author Comment

by:Ackles
ID: 22759783
Hey David,
I want to Only Export One folder.

See this is my Logic:

I will make a Rule in Outlook to put a Copy of every Incoming & Sent Item in a Sub-folder in Inbox e.g. Exported. (Because at the same time I want it to be deleted to avoid Duplication!!!)

This "Exported" folder is the one where Script has to do the Activity.

Best,
A
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 22760328
That's simple enough.  Change line #12 from the original code to the line below.
Set olkRootFolder = olkSes.GetDefaultFolder(olFolderInbox).Folders("Exported")

Open in new window

0
 
LVL 11

Author Closing Comment

by:Ackles
ID: 31508258
David,
Thanks a lot for your Kind Help!!!

On another note, I would like to ask if the same can be done on Exchange Server Side?
Would you like me to address this as a New Question or would it be possible for you to answer in this only?
Kind regards,
A
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22767281
You're welcome.  Glad I could help out.

What do you mean when you say, "if the same can be done on Exchange Server Side"?  Do you mean doing this from a process running on the Exchange server?
0
 
LVL 11

Author Comment

by:Ackles
ID: 22767831
Hey David,
Yes, I mean if the same Process can be run on Exchange Server.

Well, this is what I am thinking.... We have many Accounts & we are running Exchange Server. Now, if we could throw all the e-mails to Windows Shell right when the e-mails hit Exchange Server (without deleting them), then we don't need to run the Utility on Client Side.

I am asking as we can easily get all these e-mails then to our Document Management System for Archiving these e-mails.

Best,
A
0
 
LVL 11

Author Comment

by:Ackles
ID: 22779153
Hey David,
Any updates if this is possible?
Best,
A
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Junk folder 23 109
calendar, outlook 2 38
cached or not 5 39
Email subject no showing 2 26
Set OWA language and time zone in Exchange for individuals, all users or per database.
Use email signature images to promote corporate certifications and industry awards.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now