Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Incoming Log

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
Hi all,

In the past, I have always set up the filter process of Outlook to take incoming messages from certain people and transfer them to specific folders. I would still like to do this, but also call a VB script that would append a brief log to a specific log file (txt based). What I don't have is any good documentation on anything similar to it. Does anyone know of any good examples that would lead me in the right direction?
 
bont

I lifted this code off the net some time ago. Can't remember the site so I don't know who you should really thank.

It has a section that you could use to detect emails from certain people, and move those emails to specific folders. I don't see why you couldn't create a text file for the log (using the FileSystem.Freefile method), open if for append, and put some text in.

Hope it helps.

Steve



Public Sub ProcessEmail()
Dim myol As Outlook.Application
Dim myNS As NameSpace
Dim myInbox As MAPIFolder
Dim f1 As MAPIFolder
Dim f2 As MAPIFolder
Dim dest As MAPIFolder
Dim msg As Object
Dim ToBeDeleted() As MailItem
Dim ToBeMoved() As MailItem
Dim NumberToDelete As Integer
Dim NumberToMove As Integer
Dim idx As Integer

' Initialize variables.
NumberToDelete = 0
NumberToMove = 0
' Get a reference to the Inbox.
Set myNS = GetNamespace("MAPI")
Set myInbox = myNS.GetDefaultFolder(olFolderInbox)
' Get a reference to the destination folder.
Set dest = Nothing
For Each f1 In myNS.Folders
For Each f2 In f1.Folders
If f2.Name = "Immediate Attention" Then
Set dest = f2
End If
Next
Next
' If the destination folder wasn' t found, display
' a message and then clean up and exit.
If dest Is Nothing Then
MsgBox "The destination folder does not exist."
Set f1 = Nothing
Set f2 = Nothing
Set myNS = Nothing
Set myInbox = Nothing
Exit Sub
End If

' Loop through all messages in the Inbox.
For Each msg In myInbox.Items
' Process only mail messages.
If TypeOf msg Is MailItem Then
' If the subject contains "free", mark the
' message for deletion.
If InStr(1, msg.Subject, "free", _
vbTextCompare) > 0 Then
NumberToDelete = NumberToDelete + 1
ReDim Preserve ToBeDeleted(NumberToDelete)
Set ToBeDeleted(NumberToDelete) = msg
' If the message is from "Linda Cooper",
' mark it to be moved.
ElseIf msg.SenderName = "Linda Cooper" Then
NumberToMove = NumberToMove + 1
ReDim Preserve ToBeMoved(NumberToMove)
Set ToBeMoved(NumberToMove) = msg
End If
End If
Next
' Delete messages marked for deletion (if any).
If NumberToDelete > 0 Then
For idx = 1 To NumberToDelete
ToBeDeleted(idx).Delete
Next
End If
' Move messages marked to be moved (if any).
If NumberToMove > 0 Then
For idx = 1 To NumberToMove
ToBeMoved(idx).Move dest
Next
End If
' Clean up.
Set myNS = Nothing
Set myInbox = Nothing
Set f1 = Nothing
Set f2 = Nothing
Set dest = Nothing
Set msg = Nothing

End Sub

 
The moving files into a folder can be done using Tools/Rules Wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top