Thanks Ken for your suggestions. The code in the addin is given below. I have
added the event to the folder in InternalStartup().
public partial class ThisAddIn
{
Outlook.MAPIFolder MyFolder = null;
private Outlook.MAPIFolder CreateMyFolder()
{
Outlook.MAPIFolder MyInboxFolder =
this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
bool IsFolderExist = false;
foreach (Outlook.MAPIFolder folder in MyInboxFolder.Folders)
{
if (folder.Name.Equals("MyFolder"))
{
MyFolder = folder;
IsFolderExist = true;
break;
}
}
if (MyFolder == null || IsFolderExist == false)
{
MyFolder = MyInboxFolder.Folders.Add("MyFolder",
Outlook.OlDefaultFolders.olFolderInbox);
MyFolder.WebViewOn = false;
MyFolder.ShowAsOutlookAB = false;
MyFolder.InAppFolderSyncObject = false;
}
MyFolder.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
return MyFolder;
}
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
CreateMyFolder()
}
}
The task I want to achieve is I have list of recipients whom I have to
process. The Processing part is going to take very long time. Therefore what
I have decided is once the user clicks on the Send button, the mail will be
saved in another custom folder. Once the mail is pushed into the custom
folder, I will be performing the processing.
In this case the event attachment to the folder and the Recipient processing
resides in the Addin. As per my logic, the the processing part will be added
in the Sent Event of my Addin. First time when the user clicks on the send
button, from SentItem event I am saving that message in the custom folder
based on the origin of the mail message. When the mail is sent from the
custom folder, I will be performing the processing logic.
As per my understanding the the event attached to the custom folder does not
get fired after some time.
Please let me know I can go about making sure that the event gets fired all
the time whenever the item is inserted into that custom folder.
Your guidence will be highly appreciated.
Thanks,
Sunil
"Ken Slovak - [MVP - Outlook]" wrote:
> You do realize that the InAppFolderSyncObject property only sets whether the
> folder should be synched for the "Application Folders" SyncObject only, and
> creates that SyncObject if it doesn't exist already? So if the folder is set
> to be synched with the "All Accounts" group for example that setting won't
> have any effect.
>
> It's most likely a matter of scope. Whatever object you are using for the
> folder that you're attaching the events to must be declared at a scope level
> that is constant for as long as you want the events to fire. Otherwise the
> object and its events will go out of scope and eventually get garbage
> collected. For something like that I'd usually declare the folder object at
> a class level so it stays alive as long as the class stays alive.
>
> --
> Ken Slovak
> [MVP - Outlook]
>
http://www.slovaktech.com