To process incoming emails you need to handle the NewMailEx
event of the Application
class. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem
, MeetingItem
, or SharingItem
. The EntryIDsCollection
string contains the Entry ID that corresponds to that item. Use the Entry ID returned in the EntryIDCollection
strign to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance.
Also you may consider handling the ItemAdd
event of the Items
class (on the folder) which is fired when items are added to the folder.
You can read more about possible solutions and their pros and cons in the series of articles:
Alternatively, the email that gets sent out will always have the client number in the body, I could loop over that as well.
In that case you need to handle the ItemSend
event where you could set the MailItem.SaveSentMessageFolder property to put sent items to the folder specified. For example, the following VBA macro shows how to use the property in the code (the Outlook object model is common for all programming languages):
Sub SetSentFolder()
Dim myItem As Outlook.MailItem
Dim myResponse As Outlook.MailItem
Dim mpfInbox As Outlook.Folder
Dim mpf As Outlook.Folder
Set mpfInbox = Application.Session.GetDefaultFolder(olFolderInbox)
Set mpf = mpfInbox.Folders.Add("SaveToMySentItemsFolder")
Set myItem = Application.ActiveInspector.CurrentItem
Set myResponse = myItem.Reply
myResponse.Display
myResponse.To = "Eugene"
Set myResponse.SaveSentMessageFolder = mpf
myResponse.Send
End Sub