sachin vaid

hi ,

i am getting difficulty in using NewMailEx event of outlook add-in. It is taking only first email address as argument and not the said comma delimited string.

Please help me about why it is happening, and also the solution for it in vb.netreply me on sachin.vaid@daffodildb.com

this is the code that i am using

Private Sub outlookapp_NewMailEx(ByVal EntryIDCollection As String) Handles outlookapp.NewMailEx

Dim mai As Outlook.MailItem

Dim varEntryIDs() As String

Dim i As Integer

On Error Resume Next

varEntryIDs = Split(EntryIDCollection, ",")

For i = 0 To UBound(varEntryIDs)

mai = outlookapp.Session.GetItemFromID(varEntryIDs(i))

MsgBox(mai.SenderEmailAddress)

Next

thanks,




Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

Bill Robertson - MSFT

Hi sachin,

EntryIDCollection contains all you need to get each new mail message. The NewMailEx event will fire each time you receive a new message so there is not a collection to iterate thru, as your sample code shows. I have included sample code in both C# and VB that should give you the result you are looking for.

C#

void ThisApplication_NewMailEx(string EntryIDCollection)

{

Outlook.NameSpace outlookNS = this.GetNamespace("MAPI");

Outlook.MAPIFolder mFolder = this.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

Outlook.MailItem newMail = (Outlook.MailItem)

outlookNS.GetItemFromID(EntryIDCollection, mFolder.StoreID);

MessageBox.Show(newMail.SenderEmailAddress);

}

VB

Private Sub outlookapp_NewMailEx(ByVal EntryIDCollection As String) Handles Me.NewMailEx

Dim outlookNS As Outlook.NameSpace

outlookNS = Me.GetNamespace("MAPI")

Dim mFolder As Outlook.MAPIFolder

mFolder = Me.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

Dim newMail As Outlook.MailItem

newMail = outlookNS.GetItemFromID(EntryIDCollection, mFolder.StoreID)

MessageBox.Show(newMail.SenderEmailAddress)

End Sub

Let me know if that helps!





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

plgoldman

Bill,

I am having the same difficulty understanding the use of the "EntryIDCollecton" that Sachin is.

All of the documentation on the MSDN web site concerning programming against the "NewMailEx" event, as well as the Help Files in Outlook VBA, state that the EntryIDCollection is "A string containing entry IDs of all items received in the Inbox since the last time the event was fired. The entry IDs are comma-delimited. The maximum number of entry IDs in the string are limited only by the available memory on the computer." Excerpted from the Outlook 2003 VBA Help Files.

All of the examples for the NewMailEx event show code for looping through a comma-delimited EntryIDCollection, in fact it is called an EntryIDCollection not an EntryID.

As Sachin has found, I too find that the EntryIDCollection I get returned in the NewMailEx event only consists of one EntryID no matter how many emails are received by Outlook 2003.

In your reply to Sachin you state that "The NewMailEx event will fire each time you receive a new message so there is not a collection to iterate thru..." This statement seems to be in direct contradiction to all of the other documentation that implies that the event fires after receiving all messages that have been sitting on the server since the last time the event fired, i.e. since the last time messages were received.

My own testing confirms what Sachin has reported, when the event fires only the EntryID of the first mail item retrieved is passed to the NewMailEx event processing.

What are we missing and how do you get a hold of all of the other messages which have arrived

Your help is greatly appreciated.

Regards,

Paul





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

Sue Mosher - Outlook MVP

Apparently NewMailEx exhibits different behaviors depending on the type of mail account. With POP3 accounts, you'll definitely see a delimited string of EntryID values when Outlook is downloading a lot of messages, but some IDs won't be included if it's a really heavy load. With an Exchange account, in my testing, I never saw more than one EntryID value.

Bottom line: You can't rely on NewMailEx alone. A good supplementary approach would be to use a timer to check every 30 seconds (or longer) for unprocessed messages.





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

plgoldman

Bill - A follow up

I have finally figured out why I wasn't seeing all of the messages returned via the NewMailEx event. In all of the examples for this event I found on the MSDN web site the code being shown used the MsgBox function to display the received email info. Intuitively this did not make a lot of sense to me since MsgBox has a lot of overhead and it seems to me that the NewMailEx event processes so quickly that something should get lost somewhere. Still, that is what the examples showed so that is what I tried. Writing code with the MsgBox only resulted on getting one EntryID.

So, I decided to get rid of all the MsgBoxs and replace them with Debug.Print statements. First time out I found the "SenderEmailAddress, SentOn and Subject" information I was looking for ALL of the received messages neatly showing in the Debug Output Window.

Problem sovled.

Now what can we do about all those examples using MsgBox

Regards,

Paul





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

plgoldman

Bill - a retraction of my follow up,

Further investigation of the behavior of the NewMailEx event in my code and examining the output in the Debug Output Window has shown me that your explanation of the event is correct. It would appear that the NewMailEx event is triggered upon the arrival of each email message and not at the end of retrieving all messages pending at an MS Exchange server. That would explain why only one msgID is available each time the event handler is entered.

Knowing this I can get my MS Outlook Add-In to do what I need it to. However, I don't understand why so much of the literature talks about having a list of all delivered messages available when the NewMailEx event handler is entered. I'm writing the event handler for an MS Exchage Outlook 2003 client. Is the behavior different when Outlook 2003 is being used as a POP/SMTP client

Thanks again,

Paul





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

plgoldman

Sue,

Thank you for your response. In working with Outlook 2003 as a client on an MS Exchange 2003 server the NewMailEx event is definitely triggered each time a new mail item is downloaded from the server. I tested my Add-In very carefully using Debug.Print to trace the activity within my NewMailEx event handler.

Within the NewMailEx event handler I created two logical paths: one for the case when there was a delimited string of EntryID values, i.e. InStr(EntryIDCollection, ",") > 0 and when it was = 0. The Debug.Print call in the >0 case would output the message originator, message subject and message sent time and the character string "multiple" and the =0 case would output the same message header information and the charcater string "single." I left the Outlook2003 client running for a few hours and inspection of the Debug window for my Add-In showed that the header information for every message received by the client had been successfully captured and in every case the character string "single" appeared.

Knowing this I am able to get the Add-in to do what I need it to.

However, the complete lack of documentation regarding the differences in behavior relative to POP and MS Exchange servers did prove a bit frustrating. On the other hand I certainly did learn a whole lot trying to track it down myself. As I professor I once had in grad school told me "If you provide all of the information necessary to solve a problem, no one learns anything."

Again, Thanks for your response,

Paul





Re: Visual Studio Tools for Office Outlook 2003's NewMailEx event handling in vb.net

Rahul Shende

Hi All

I am getting difficulty while accessing the Sender Email Address. I am using .SenderEmailAddress property of

Microsoft.Office.Interop.Outlook.MailItem.

I am good till I receive mails from outside domain (getting address like shende.rahu77l@gmail.com)

but when I receive mails from same domain I am getting address in active directory format.(/O="eda"/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN="rshende"). I want it normal format like rshende@eda.com

Please help me in this regard. You can drop a mail rearding it on shende.rahul77@gmail.com

Private WithEvents m_oSess As Microsoft.Office.Interop.Outlook.Application

Private m_oApp As Aptify.Framework.Application.AptifyApplication

Public Sub Configure(ByVal oApplication As Aptify.Framework.Application.AptifyApplication)

m_oApp = oApplication

m_oSess = New Outlook.Application()

Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = m_oSess.GetNamespace("mapi")

Dim oInbox As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)

End Sub

Public Sub ProcessMessage(ByVal oMailItem As Microsoft.Office.Interop.Outlook.MailItem)

MsgBox(oMailItem.SenderEmailAddress.ToString)

End Sub

Thanks

Rahul S.