Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Outlook Item Add Event for mutliple items

Posted on 2009-05-06
16
Medium Priority
?
1,064 Views
Last Modified: 2012-05-06
Hi experts,

  I need to maintain a log of the mails that i have received, i am using the item add event for the same. However the problem is that the event is triggered only once if multiple items are received at a time. How can i get details of all the mails that have arrived?
0
Comment
Question by:hiteshgoldeneye
  • 9
  • 7
16 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24312196
Assuming you are using NewMailEx then see below

Chris
Private Sub NewMailEx(ByVal EntryIDCollection As String)
Dim mai As mailitem
Dim strEntryID() As String
Dim intFinal As Integer
Dim testObj As Object
 
    strEntryID = Split(EntryIDCollection & ",", ",")
    For intFinal = 0 To UBound(strEntryID) - 1
        Set testObj = Application.Session.GetItemFromID(strEntryID(intFinal))
        If testObj.Class = olMail Then
            set mai = testobj
' Process your email here
        end if
    next
'...

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24312228
Re-reading then of course this is not the add event to the folder BUT it is a mechanism for processing all the received mails in a batch.

Chris
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24312285
when can the above procedure be called? Does it get called automatically when new mails are received?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24312363
It is automatically called and resides in thisoutlooksession as one of the application events.

i.e. the correct sub name is:

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)

Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 24312377
FYI

Because I often generate this event handler for different Questions in EE I call out from the Application_NewMailEx sub to a question specific variant so my apologies for the misleading naming of the original post.

Chris
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24312658
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24312698
>>> hi chris can you help me with this question as well?

Sorry I am not familiar with C# so totally useless in that regard

Chris
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24482468
Hi BlueDevilFan, I am facing one problem with the solution, I am trying to use the event you mentioned, however there is a rule set on the client machine which moves the mail to a particular folder, and the newmailex item is not triggered :(.
Can u help in this?
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24490241
sorry i should have mentioned Chris not BlueDevilFan
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24490706
Can you upload your code for newmailex and the settings used for their rule.

In the meantime I will look at precedence for code

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24490759
I have looked to confirm precedence and it is as I would expect, newmailex fires before the rule therefore I would suspect the implementation of code on their PC, and is teh reason I requested the code details.

Chris
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24491180
Hi Chris thanks for your feedback, actually i had checked the documentation on msn regarding this event and it mentioned the same thing that the event fires before any rules are applied. However i dont know why i am facing an issue, the client is busy currently so i am not able to work on the m/c. So will reply to you soon.
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24491713
HI chris i tried to debug the problem, but surprisingly the event doesnt trigger on the Client's mc (works for Default Inbox only).

 Also I tried to use the code in my machine (after modifying it suitably),I got an error in the line
Set testObj = Application.Session.GetItemFromID(strEntryID(intFinal))

I think this is because the mail must have moved to the personal folder and as u know the EntryId is changed by Outlook once a mail is moved. So i guess it means that the entire code in the event is not executed before the rule is applied :(. The code i used is attached herwith.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
 
Dim mai As MailItem
Dim strEntryID() As String
Dim intFinal As Integer
Dim testObj As Object
Dim i As Integer
Dim SenderAddress As String
Dim sqlQuery As String, MailType As String
 
MailType = "External"
strEntryID = Split(EntryIDCollection & ",", ",")
For intFinal = UBound(strEntryID) - 1 To 0 Step -1
        If intFinal = UBound(strEntryID) - 1 Then
            constr = "Data Source=blah;Initial Catalog=blah;User Id=sa;Password=blah;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;"
            Set con = New ADODB.Connection
            con.Open constr
        End If
        Set testObj = Application.Session.GetItemFromID(strEntryID(intFinal))
        If testObj.Class = olMail Then
            Set mai = testObj
            If mai.To = "IN, Consultingschool" Then
                    SenderAddress = R_GetSenderAddress(mai)
                    If InStr(1, UCase(SenderAddress), UCase("marijke.dekker@capgemini.com"), vbTextCompare) > 0 Then
                        MailType = "Internal"
                    End If
                    If InStr(1, UCase(SenderAddress), UCase("severine.cano@capgemini.com"), vbTextCompare) > 0 Then
                        MailType = "Internal"
                    End If
                    If InStr(1, UCase(SenderAddress), UCase("lorna.ball@capgemini.com"), vbTextCompare) > 0 Then
                        MailType = "Internal"
                    End If
 
                    sqlQuery = sqlQuery & "'" & SenderAddress & "'," 'Replace(mai.SenderName, "'", "") & "'," 'GetReplyToAddress(mai)  '.SenderEmailAddress
                    sqlQuery = sqlQuery & "'" & Replace(mai.To, "'", "") & "',"
                    sqlQuery = sqlQuery & "'" & Replace(mai.Subject, "'", "") & "',"
 
                    sqlQuery = sqlQuery & "'" & Month(mai.ReceivedTime) & "/" & _
                    Day(mai.ReceivedTime) & "/" & Year(mai.ReceivedTime) & " " & _
                    Hour(mai.ReceivedTime) & ":" & Minute(mai.ReceivedTime) & ":" & _
                    Second(mai.ReceivedTime) & "','" & MailType & "')"
                    con.Execute sqlQuery
            End If
       End If
 Next
 con.Close
 
End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24525742
HI chris i tried to debug the problem, but surprisingly the event doesnt trigger on the Client's mc (works for Default Inbox only).

>>> Stupid question maybe but is the code located in thisoutlooksession and is it the only so named sub?

Chris
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 24525791
Yes Chris, it is located in thisoutlooksession and is the only so named Sub (we get a compiler error Ambiguous name detected when you have 2 Sub with same name right?)
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24529442
>>> we get a compiler error Ambiguous name - COrrect

MAcros enabled?

BUT:::::

>>> i tried to debug the problem, but surprisingly the event doesnt trigger on the Client's mc (works for Default Inbox only).

The receive event fires off the default mailbox so am I missing some detail?

Chris
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question