Saving email to files

I would like to save copies of emails send on a project-by-project basis.  For example, to a folder related to a specific client or job.  Is there any practical way to do this?
Who is Participating?
rosesolutions1Connect With a Mentor Commented:
OK - now to identify which ones go where, you can
(a) use outlook categories (unlimited cateogirs, so nice)
(b) use outlook flags (only a restricted set of options)
(c) link the items to Contacts (best outcome bcause adds functionality to Outlook, but may be slowest to do)
(d) store the items in different Outlook folders, and automatically write to disk all the messages that get stored in those folders - how do you organise your inbox?

Create a new folder underneath Inbox based upon the Project/Client information.
You can set up a rule, if there's some identifier with each email to move these automatically to these folders.
If you want to save them to your hard drive - open up your documents folder - create a new folder corresponding to the project/client information.
Set up both your email and document folder where you can see both.  Select all emails from the outlook folder (ctrl + A) - now drag and drop them all into the document folder...
That will result in .msg files, which might be fine for your purposes.
I needed files that could be read with Outlook being installed, so wrote code to dump text in txt, rtf in rtf, and html in html (as well as attachments in their native formats). Do you need that?
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

GregorySingerAuthor Commented:
I may not have been clear enough.  I understood how to save emails received based on folders and rules.  What I'm trying to ask is if there's a way to autmatically save a "carbon-copy" of an outgoing email to a specific folder, representing a client, project, etc?
Sure. Are you happy with .msg files, or do you want .txt;.rtf & .html?
(Note: in general, search engines wont search .msg files, so if you want the store to be searchable, you need to check whether yours will search the contents of .msg (and, presumably, the contents of attachments.)
GregorySingerAuthor Commented:
To:  rosesolutions1
Searching the stored messages is not critical, but desireable.
How can I implement your suggestions?
>>What I'm trying to ask is if there's a way to autmatically save a "carbon-copy" of an outgoing email to a specific folder, representing a client, project, etc?<<
Do you mean an Outlook folder?  If so, simply apply a rule for all outgoing messages....
GregorySingerAuthor Commented:
Do I mean an Outlook folder?
Actually no.  The reason is that I utilize a "conventional" system file folder to hold a variety of project related items such as spreadsheets (for estimates), Word docs (proposals, etc.), etc. etc.  It would be very helpful to be able to save outgoing copies of emails directly and automatically to such a folder on a project-by-project basis.
Ew - I was afraid of that....I do a bit of coding myself - but for some reason Outlook's VBA gives me the creeps...
I've got someone in mind that may be able to lend a hand though - I'll try to get a hold of her...stay tuned.
GregorySingerAuthor Commented:
Much obliged.  Sounds interesting!
She's extremely sharp - I think I'll hang along for the ride - I just might learn something too.  :D
GregorySinger, Sirbounty,
It would be a pleasure to help GregorySinger but  rosesolutions1 already offered to post the code to copy outgoing mails to HD. I had seen this post before when published and when Rosesolutions1 popped in, I did not want to interfere...
Neverthelss, whoever works on this project, we will need more info: how to determine that an outgoing mail must be saved to HD? Subject content?

BTW: I should sign sir-stefri (Ste is the beginning of my first name Stephane which is equivalent to the Anglo-Saxon first name Steve, Stephen, Stevie...The female first name is Stephanie ;-).
My apologies!  I was typing "him" and then changed my mind...not wanting to offend anyone - but alas, looks like I may have after all.  :(
no problem....once dreamboat wrote I was a doll....
GregorySingerAuthor Commented:
Stefri, Rosesolutions1
Stefri: I didn't interpret rosesolutions1 reply as having code to do what I wanted.  If I'm wrong, I apologize.  And rosesolutions1, I'd like to see the code.
Stefri, you also bring up a good point as to how and when to do this copying.  The ideal scenario would be to have some mechanism to flag the code so that the HD file (location)  could be put in the "cc" box, and that would trigger the copying. Or, a special field on a custom email form that when filled in would trigger the copying.
Any others ideas are welcome.  Thanks!
If you want a no-code method, then check out the Save Message action of the product InboxRules. <

For a code method, the code below saves a selected email (or group of emails) to disk. Get this bit working, and then we can talk about how to make it automatic...

Sub blulksaveout()
Dim selItems As Outlook.Selection
Dim objItem As Object
Dim x As Long
Dim strPath As String, strFullName As String, strName As String
On Error GoTo myerr

Set selItems = Application.ActiveExplorer.Selection
strPath = InputBox("Where would you like to save the " & selItems.Count & " items selected?" & vbNewLine & "(eg C:\MyFiles)", "Bulk Save Utility", "C:\temp")
If Len(strPath) > 0 Then 'else they hit cancel
    If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1) 'catch "C:\"
    For x = 1 To selItems.Count
        Set objItem = selItems.Item(x) 'some of the properties used below are mailitem only
        If TypeName(objItem) = "MailItem" Then
            strName = MakeStringValid(objItem.Subject) 'Format(objItem.SentOn, "yymmdd") & " " &
            Select Case objItem.BodyFormat
                Case olFormatHTML
                    strFullName = strPath & "\" & strName & ".htm"
                    objItem.SaveAs strFullName, olHTML 'olSaveAsType constant for HTML only works if the item is HTML
                Case olFormatPlain
                    strFullName = strPath & "\" & strName & ".txt"
                    objItem.SaveAs strFullName, olTXT
                Case olFormatRichText
                    strFullName = strPath & "\" & strName & ".msg"
                    objItem.SaveAs strFullName
                Case olFormatUnspecified
                    strFullName = strPath & "\" & strName & ".msg"
                    objItem.SaveAs strFullName
            End Select
        End If
        Set objItem = Nothing
    Next x
End If
    Set objItem = Nothing
    Set selItems = Nothing
Exit Sub

myerr: 'std
    Dim intReturn As Integer
    intReturn = MsgBox(Err.Number & " - " & Err.Description, vbAbortRetryIgnore)
    Select Case intReturn
        Case vbAbort
            GoTo exit_sub
        Case vbRetry
            'make debugging invalid character list a bit faster...
'            strName = MakeStringValid(objItem.Subject) 'Format(objItem.SentOn, "yymmdd") & " " &
'            strFullName = strPath & "\" & strName & ".htm"
        Case vbIgnore
            Resume xx_Continue
    End Select
End Sub

Function MakeStringValid(StringToTest As String) As String
Const strBadChars As String = "@#$%^&: ?-()'\/"
Dim strInUse As String
strInUse = StringToTest
    Dim x As Integer
    For x = 1 To Len(strBadChars)
    Dim y
        y = Mid$(strBadChars, x, 1)
        If InStr(1, strInUse, y, 0) Then
            strInUse = Replace(strInUse, y, "_")
        End If
    Next x
'untested supplement that we may need later...
'    Const badascii As String = "34091013" 'double quote, tab, line feed, carriage return
'    For x = 1 To Len(badascii) / 2
'        y = Mid$(badascii, x * 2, 2)
'        If InStr(1, strInUse, y, 0) Then
'            strInUse = Replace(strInUse, y, "_")
'        End If
'    Next x
    MakeStringValid = strInUse
End Function
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.