PDA

View Full Version : Solved: ItemAdd Event



kbsudhir
12-27-2007, 09:43 AM
Hi All,

I want to capture the attributes of the mails as soon as they come into the inbox.

Tony advised to create a rule which will run the script to capture the mails, whcih is working fine but I can't implement this technique on the common inbox hence I have change the approach.

I found out that Itemadd event can be used to capture as soon as a new item is added to folder. But am not able to understand its implementation.

Secondly Itemadd event will not work when there bulk of mails come to inbox together. To solve this problem I think Itemadd is to used along with Newmail event as this event is generated for each and every mail coming to the inbox. Is it possible to call itemadd event from newmail event hence the problem of lot of mails coming to the inbox can be resolved.

I am using Outlook 2003

Any guidence in this regard is appreciated.

:dunno

Thanks
Sudhir

ofrazier
12-31-2007, 06:29 PM
From what I have seen, that event does not include any information on the new message coming into the inbox, it is simply a trigger.

Without knowing more, I can only speculate that you may want to check the content of the inbox upon each triggered event to workaround this.

google "how to process incoming messages in MS Outlook"

kbsudhir
01-03-2008, 04:16 PM
We have to use NewMailEX

Below is the code u will not even get the outlook security alert message.

Private Sub Application_NewMailEx _
(ByVal EntryIDCollection As String)
Dim arr() As String
Dim i As Integer
Dim ns As Outlook.NameSpace
Dim itm As MailItem
Dim NewItem As Outlook.MailItem
On Error Resume Next
Set ns = Application.Session
arr = Split(EntryIDCollection, ",")
MsgBox (arr)
For i = 0 To UBound(arr)
Set itm = ns.GetItemFromID(arr(i))
If itm.Class = olMail Then
Set NewItem = itm
MsgBox (NewItem.Subject)
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Sudhir\Outlook.mdb;"
'open a recordset
Set rs = New ADODB.Recordset
rs.Open "select * from Outlook", cn, adOpenStatic, adLockOptimistic
rs.AddNew
rs.Fields("Subject") = NewItem.Subject
rs.Fields("ReceivedDateTime") = NewItem.ReceivedTime
rs.Fields("From") = NewItem.SenderName
rs.Fields("To") = NewItem.To
rs.Fields("CC") = NewItem.CC
rs.Fields("Importance") = NewItem.Importance
rs.Fields("SenderNameEmailID") = NewItem.SenderEmailAddress
rs.Fields("ConversationIndex") = NewItem.ConversationIndex
rs.Fields("Identifier") = Left(NewItem.ConversationIndex, 40)
rs.Fields("MessageBody") = NewItem.Body

rs.Update
rs.Close
End If
Next
Set ns = Nothing
Set itm = Nothing
Set NewItem = Nothing

End Sub

Thanks
Sudhir
:cloud9: