Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 36 of 36

Thread: Solved: save e-mails to local disk

  1. #21
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    Ok ran the code with it commented out and the box that come up has Ok and help in it. If I click help it opens the help dialog to syntax error.


    I ran the script on the root "personal folder" and it does not give the error, as soon as I pick a folder under the root of personal is when I get the error.

  2. #22
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    Did not get a compile error.

  3. #23
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by korgul
    Ok ran the code with it commented out and the box that come up has Ok and help in it. If I click help it opens the help dialog to syntax error.
    Huh...Only Ok and Help?....Is you're VBA project protected in some way....

    Very strange! Can't remember Outlook 2000 to well so it's possible that those buttons are the only to provided..(I'll see when I get home)

    I ran the script on the root "personal folder" and it does not give the error, as soon as I pick a folder under the root of personal is when I get the error.
    So You get the folderpicker to choose a folder and it does work on some but not on others....

    Again I don't understand this I've run this code under several folders including a subfolder of Inbox (in Personal folders)

    Can you do the compile thing for me I've asked before?

    O and what is your exact OS and Office? (2000) I presume but are you also on exchange?

    I hope we fry this puppy soon!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  4. #24
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    Ok OS = XP, E-mail = 2000, no exchange server

    Yes I get the folder picker put can only run it on the personal folder. If I pick a sub folder I get the error.

  5. #25
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Mighty strange my friend must have something to do with the loos attached *pst files I think..

    But try this separate sub:[VBA]
    Sub FolderName()
    Dim oNameSpace As Outlook.NameSpace, oTargetFolder As Outlook.MAPIFolder

    Set oNameSpace = Application.GetNamespace("MAPI")
    Set oTargetFolder = oNameSpace.PickFolder

    If TypeName(oTargetFolder) <> "Nothing" Then
    MsgBox oTargetFolder.Name
    End If

    Set oTargetFolder = Nothing
    Set oNameSpace = Nothing
    End Sub
    [/VBA]

    Run it several times and check that you get the correct name of the chosen folder in the messagebox.

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  6. #26
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    Ok I plugged that in. When I run it now I get the message box with the folder name that I selected.

  7. #27
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by korgul
    Ok I plugged that in. When I run it now I get the message box with the folder name that I selected.
    Ok that's good news at least the folder name is found by the code. So somehow something else is going wrong.

    I'll have to stop for the night and try the code out when I get home.

    So I'll see you tomorrow.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #28
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Ok did my test on a 2000 machine and all runs well!

    Frustrating h?...

    This leads me to believe that the emails you're receiving might have a different layout then I acspect them to be.

    The code deals with a specific format of the emails and is definitifly not foolprooff!

    So I tried to add some normal emails to the folder to process and I found out I could duplicate your error if my mailreading code picked up some unwanted character in a file path.

    So could you please send me some of your virus emails so I can test on those to see if the format is different then I acspect? Send to: joost@webforums.nl

    For now I couldn't find anything wrong with the code so it could also be an enviroment issue on your site....(That will be hard to find)

    Till tomorrow...have to sleep now!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #29
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    On there way.

    I agree it is very odd that it would work on yours but bomb out on mine. Most likely it is something that I am doing. Again, I am very new to VBA, but have some coding experience with VBScript.

  10. #30
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    I'm sure it has nothing to do with you, so hold on...I'm in it till the end aswell!

    Have received your emails and the code runs on it like a knive trough butter!

    But I did notice there where special caracters in the computer names and I do wonder if maybe on of those files has a caracter in (The computername) it that is not allowed in a file path.

    To find this out we need to run some debug code!

    So copy this altered code in a new module and run it:[VBA]
    Option Explicit

    Const sSearch As String = "Computer: "
    Const sBase As String = "c:\virus-related\"

    Sub SaveEmailToText()
    Dim oNameSpace As Outlook.NameSpace, oTargetFolder As Outlook.MAPIFolder
    Dim oMailToProces As Outlook.Items, oMail As Outlook.MailItem
    Dim sDate As String, sPath As String, sName As String

    On Error GoTo UnExpected
    Set oNameSpace = Application.GetNamespace("MAPI")
    Set oTargetFolder = oNameSpace.PickFolder

    If TypeName(oTargetFolder) <> "Nothing" Then
    Set oMailToProces = oTargetFolder.Items

    If TypeName(oMailToProces) <> "Nothing" Then
    For Each oMail In oMailToProces
    If (oMail.Class = olMail) Then
    sDate = Format$(oMail.ReceivedTime, "Short Date")
    Debug.Print "Date received: " & sDate

    Debug.Print "Base: " & sBase
    If fExists(sBase) = False Then MkDir Path:=sBase
    sPath = LCase(sBase & sDate)
    Debug.Print "Folder to save: " & sPath

    If fExists(sPath) = False Then MkDir Path:=sPath
    sName = SearchComputer(oMail.Body)
    Debug.Print "Computername: " & sName

    sPath = LCase(sPath & "\" & sName & ".txt")
    Debug.Print "File path: " & sPath

    oMail.SaveAs Path:=sPath, Type:=olTXT
    End If
    Next
    End If
    MsgBox "Done!"
    End If

    UnExpectedEx:
    Set oTargetFolder = Nothing
    Set oNameSpace = Nothing
    Exit Sub

    UnExpected:
    Debug.Print Err.Number & " "; Err.Description
    MsgBox Err.Number & " " & Err.Description
    Resume UnExpectedEx
    End Sub

    Private Function SearchComputer(sBody As String) As String
    Dim iSearch As Integer
    Dim iName As Integer
    Dim sComputer As String

    iSearch = InStr(1, sBody, sSearch, vbTextCompare)
    iSearch = (iSearch + Len(sSearch))

    If iSearch = 0 Then
    SearchComputer = "NOT FOUND"
    Exit Function
    Else
    iName = InStr(iSearch, sBody, Chr$(13), vbTextCompare)
    sComputer = Mid(sBody, iSearch, (iName - iSearch))

    SearchComputer = Trim(sComputer)
    End If
    End Function

    Public Function fExists(ByVal sFile As String) As Boolean
    If Right$(sFile, 1) <> "\" Then sFile = sFile & "\"

    If Dir(sFile, vbDirectory) <> "" Then
    fExists = True
    Else
    fExists = False
    End If
    End Function
    [/VBA]

    After you run it open de VBE and press CTRL+G this will open a debug window (Called "direct" in dutch)

    There will be information written in it so copy all of that (IF much into a notepath) and attached it here (Enclosed in VBA tags) so I can get the info required out of there.

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #31
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    [VBA]Date received: 5/27/2005
    Base: c:\virus-related\
    Folder to save: c:\virus-related\5/27/2005
    76 Path not found
    [/VBA]



    This is the message that I get from the de bugger.

  12. #32
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    It looks like it is trying to create the folder c:\virus-related\5/27/2005 and this is where it is bombing out.

  13. #33
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    I got it working. I changed this line in the code.


    sDate = Format$(oMail.ReceivedTime, "Short Date")

    to this

    sDate = Format$(oMail.ReceivedTime, "m-dd")

    Now when I run it, it will create the folder with todays date and then copy the mail into it.

    Thanks for all of your help on this.

  14. #34
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by korgul
    It looks like it is trying to create the folder c:\virus-related\5/27/2005 and this is where it is bombing out.
    Hi,

    Great it's working now! You're most welcome!

    I knew it had to be something in the environment! "Short Date" over here returns : "05-27-2005" so that's ok for a file path!

    This has everything to do with regional and country settings in Control Panel. Totally overlooked this stupid mistake!

    O wel good to see you noticed youreself that it's not allowed to have a: "\" or a "/" in the wrong place in a filepath!

    Can I make one suggestion:
    I would make this change:
    sDate = Format$(oMail.ReceivedTime, "mm-dd-yyyy")

    This formats as: 05-27-2005 and this if better if you're using this for a longer period than a year otherwise you run out of folders!!!!


    So tell me....How much time does my macro save you each day!

    Enjoy!
    Ps..please don't forget to mark your thread solved!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  15. #35
    VBAX Regular
    Joined
    May 2005
    Posts
    17
    Location
    Having the format as m-dd is not a problem as I will be deleting the folders as they get cleaned out or too old ( over a week ).

    This saves a tremedous amout of time. What would take me over 2 hours to do not goes by in only secs.

    This was the first part of a three part process. I now have part 1 and 2 done. Now onto part three.
    The second part goes through the folders picks out the name of the file, reads 3 lines from the file and writes it to a log file. Then saves the log file as the folder name. It creates one log file for each folder.

    Part three will go through the log files and pick out the file names that are duplicated and write them to another file. That way we can see which computers keep getting infected.


    Thanks again for all of your help.

  16. #36
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by korgul
    Having the format as m-dd is not a problem as I will be deleting the folders as they get cleaned out or too old ( over a week ).

    This saves a tremedous amout of time. What would take me over 2 hours to do not goes by in only secs.
    Thanks again for all of your help.
    It's great to hear it saves you so much time! That's the mean reason for coding stuff and people ussualy dont believe it but when they see it they all go: Aaaaaaaaaahhhhhhhh!

    Well good luck on Fase II & III and I'm shure you'll gane even more time and finish you're desired Analytical tool.
    (And Punish those who keep getting infected! )

    Till we meet again...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •