Hi,
you can do this by handling the events for the folders..
<code>
..
// get MAPI namespace
Outlook.NameSpace mapiNamespace = this.GetNamespace("MAPI");
// get Outbox Folder .. sent mails will be added there before sending
Outlook.MAPIFolder _outboxMailFolder =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
// handle add item event
outboxMailItems.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(outboxMailItems_ItemAdd);
...
//the add item event handler:
void outboxMailItems_ItemAdd(object Item)
{
Outlook.MailItem _newMail = Item as MOutlook.MailItem;
if (_newMail != null)
{
try
{
//do whatever you want with the mail...
}
finally
{
// send the mail (seems this is not done
automatically when handling the itemadd event...
_newMail.Send();
}
}
}
...
Philipp
_______________________
> Hi,
>
[quoted text clipped - 13 lines]
> Thanks
> Andy
Andy - 29 Jun 2006 13:23 GMT
Ahh, sounds like a better approach.
Thanks
Andy
> Hi,
>
[quoted text clipped - 34 lines]
>
> Philipp
Andy - 29 Jun 2006 20:27 GMT
Hey Philipp,
I wired up the events as you suggest, and i keep a reference to the
folder objects. Everything works (it doesn't seem like I needed tell
the message to send, but i'm using the Sent mail box instead of the
outbox). The only problem is when I try to remove the event handlers
on application shutdown, i get a null reference exception.
Any ideas how I can properly remove my event handlers?
Thanks
Andy
> Hi,
>
[quoted text clipped - 34 lines]
>
> Philipp
Andy - 30 Jun 2006 21:17 GMT
Got it figured out; had to keep a reference to the Items (not just the
mailbox) and from a blog on msdn, you also have to keep those
references static.
Everything works as expected now.
Andy
> Hey Philipp,
>
[quoted text clipped - 8 lines]
> Thanks
> Andy