Fire event when mail is arrives in sentmail folder

Hi All

Hope you can help

I want to be able to access an email that has just been sent. To do this I need to know when an email is added to the sentmail folder.

I am using VS2005.NET and VSTO with Outlook 2003.

The project is in Visual Basic.

I have seen this sort of thing in c#

public void OnStartupComplete(ref System.Array custom)
{ // add the handler to default folder's ItemAddEvent...
mapi = outlook.GetNamespace("MAPI");
inbox =
mapi.GetDefaultFolder(Outlook.OlDefaultFolders.olF olderInbox);
inbox.Items.ItemAdd +=
new Outlook.ItemsEvents_ItemAddEventHandler(InboxItems _ItemAdd);
}

but can't seem to convert this line to VB

inbox.Items.ItemAdd +=
new Outlook.ItemsEvents_ItemAddEventHandler(InboxItems _ItemAdd);

Thanks in advance

Colin




Answer this question

Fire event when mail is arrives in sentmail folder

  • TungNguyen

    Hi Cindy

    I have worked it out now. To help others trying to do the same thing here is my code.

    Dim _outboxFolder As Outlook.MAPIFolder
    Dim WithEvents _outboxItems As Outlook.Items

    Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    _outboxFolder = ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
    _outboxItems = _outboxFolder.Items
    AddHandler _outboxItems.ItemAdd, AddressOf outboxFolderItemAdded
    End Sub

    Private Sub outboxFolderItemAdded(ByVal Item As Object)
    MsgBox("outboxFolderItemAdded")
    End Sub

    Regards

    Colin



  • Chee Yong

    I thought about tackling this problem this way, and there are a few problems inherent with this approach. It assumes the folder is named "Sent Items" and it assumes that messages are saved somewhere on send. Both of these IIRC can be configured. I decided for my purposes that it was kind of hokey and just included the issues I had with processing immediately prior to send as known issues that couldn't be resolved.

    FYI - The ItemSend event if canceled will put the user back at the message editor, and happens when the message is scheduled to be sent, not when it is added to the outbox. To see this, set up Outlook to work in offline mode and "Send" a message. It will be added to the outbox, but the event will not fire until the message has actually being prepared to be sent.


  • sidnic

    John

    To clarify my problem for you, I am currently using the itemsend event. This acts upon the message before it is actually sent, and I want to manipulate it after it has been sent.

    I had downloaded the VSTO samples (the same ones as the link on your page) and there is OutlookEvents sample code. This works well. However it is in c# (not a big problem) and it uses Microsoft.Office.Tools.Outlook.dll ver 8.0.0.0. My application uses ver 9.2.0.0 and the events have changed.

    If it is a bread and butter task, maybe you could share a few lines of code or a link to an appropriate example as my searches on Google have been fruitless.

    Secondly, appologies if I have posted in the wrong group. But as I am using VSTO and VS2005 to create an outlook com addin, I thought this would be the group! Please can you tell me where I should post

    Regards



  • dc33428

    Hi Colin

    Unfortunately, Outlook just isn't my thing, but...

    You might try in the Office developer group for Addins. Keep an eye out for Ken Slovak, who does frequent that newsgroup. He's not only an Outlook guy, he's also into .NET-speak and Addins :-)

    http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US

    If you do get help there, I'd appreciate you're coming back and marking this thread as "answered" (an administrative thing).



  • Arumugam

    Colin,

    Responding to events in the Outlook folders is a bread-and-butter task. You need to get much more familiar with the Outlook object model, and there are LOADS of examples in VB. I have written a number of samples in C# and VB.NET that contain code you could easily use.

    It is helpful to remember that this forum is mainly for issues that directly pertain to the Visual Studio Tools for Office tools per se. So you will be best served by posing this question to a forum or newsgroup wholly dedicated to application-specific issues such as yours. Here is a link to resources that will help you:

    http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx

    John.



  • Leton

    Thanks for the response Nick

    The anoying thing is I have a VSTO example in c# to do just this. You can download it here -> http://msdn.microsoft.com/office/tool/vsto/2005/training/samples/default.aspx

    but it uses an old dll that has different events, and I can't seem to find any documentation or examples of doing the same thing with the current version.

    Mabe someone has already tackled this problem.

    Thanks for your help.



  • Fire event when mail is arrives in sentmail folder