Solved

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

Posted on 2008-10-16
16
476 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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