home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1711
Discussions: 188,401, Posts: 2,243,608, Members: 232,631
Old April 8th, 2005, 05:20 PM   Digg it!   #1 (permalink)
Ultimate Member
 
korgul's Avatar
 
Join Date: Oct 2001
Location: York, PA.
Posts: 1,569
Is it possible

First a little background

I take care of a mailbox here at work that receives notifications from our antivirus program when it finds a virus on a computer. All of the E-mails that are received into the mailbox have the same subject line. Now, we might receive 10 or more from one machine. The only way that I can see which machine is infected is if I open the E-mail. Opening 10, 20 or even 30 is not so bad. Opening over 800 in a day takes some time. What I want to do is have a script that will automaticaly save the E-mails as a text file to the C drive. Then go through the body of the newly created txt file and pull the machine name out of the E-mail, then save the E-mail as machinename.txt. After it is done renaming the txt files I want to delete any that might be duplicates.

Is this possible?

korgul

korgul is offline   Reply With Quote
Old April 8th, 2005, 05:27 PM     #2 (permalink)
Ultimate Member
 
-FMA's Avatar
 
Join Date: Oct 2004
Location: Michigan~
Posts: 2,715
Send a message via AIM to -FMA Send a message via MSN to -FMA
Its probably possible, I don't know how but thats a great idea!

-FMA is offline   Reply With Quote
Old April 8th, 2005, 05:52 PM     #3 (permalink)
Ultimate Member
 
meese's Avatar
 
Join Date: Jun 2003
Location: NJ
Posts: 2,467

meese is offline   Reply With Quote
Old April 14th, 2005, 10:26 AM     #4 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,026
Heya Korgul, long time no see!

Korgul, a few ways you can do it
is this with ms exchange?
Do you have public folders?
You can put an events script on a public folder that when it receives a message will run a specified script.

Otherwise, its fairly easy to write a script that attaches to outlook, and gets a collection of the messages to parse through them.

Here's a sample script I whipped up real quick

Quote:
Const olFolderInbox = 6

Set oOutlook = CreateObject("Outlook.Application")
Set olns = oOutlook.Application.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set oInbox = olns.GetDefaultFolder(olFolderInbox)
' Set MyItem to the collection of items in the folder.
Set oAllMail = oInbox.Items
For Each oMail in oAllMail
wscript.echo oMail.Body
Next
Now with oMail.Body you can put that into a text file using FSO

SO without further ado... <drum roll>

you can do something cheesy like this!

Code:
Const olFolderInbox = 6

Set oOutlook = CreateObject("Outlook.Application")
Set olns = oOutlook.Application.GetNameSpace("MAPI")
' Set MyFolder to the default contacts folder.
Set oInbox = olns.GetDefaultFolder(olFolderInbox)
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set MyItem to the collection of items in the folder.
Set oAllMail = oInbox.Items
For Each oMail in oAllMail
  wscript.echo oMail.Body
  Set objFile = objFSO.CreateTextFile("C:\Temp\" & oMail.Subject, True)
  objFile.Write oMail.Body
  objFile.Close

Next
This will at the very least get you started
Sorry didn't see this last week :/
vass0922 is offline   Reply With Quote
Old April 14th, 2005, 10:41 AM     #5 (permalink)
Ultimate Member
 
korgul's Avatar
 
Join Date: Oct 2001
Location: York, PA.
Posts: 1,569
Cool
Thanks Vass I will see what I can do. Thanks for the help.

Yes it has been awhile since I was here last. Been really busy lately.
korgul is offline   Reply With Quote
Old May 31st, 2005, 02:36 PM     #6 (permalink)
Ultimate Member
 
korgul's Avatar
 
Join Date: Oct 2001
Location: York, PA.
Posts: 1,569
Ok got it working with a macro in outlook.
Code:
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, "m-dd")
                    If fExists(sBase) = False Then MkDir Path:=sBase
                    sPath = LCase(sBase & sDate)
                     
                    If fExists(sPath) = False Then MkDir Path:=sPath
                    sName = SearchComputer(oMail.Body)
                    sPath = LCase(sPath & "\" & sName & ".txt")
                     
                    oMail.SaveAs Path:=sPath, Type:=olTXT
                End If
            Next
        End If
        MsgBox "Done!"
    End If
     
     End

UnExpectedEx:
    Set oTargetFolder = Nothing
    Set oNameSpace = Nothing
    Exit Sub
     
UnExpected:
    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
Wanted to let you all know.
korgul is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Unarmed man on his stomach shot by .. (6)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
For cheap price and good qualit.. (1)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:12 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28