Question

I want to save a copy of a sent mail item in a specific folder.

The below code is fired when hitting "send".

The item is saved in the folder as an unsent email item (Outlook shows the message: "This message has not been sent"). I want it saved as a sent item (just like the folder "sent items").

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo ErrorHandler

Dim moveToFolder As Outlook.MAPIFolder
Dim myCopiedItem As Outlook.MailItem
    
Set ns = Application.GetNamespace("MAPI")
Set moveToFolder = ns.Folders("Mailbox - My Mailbox").Folders(".Waiting_for")

With Item

    If InStr(Item.Body, "/wf") > 0 Then
        Set myCopiedItem = Item.copy
        myCopiedItem.Move moveToFolder
    Else
    End If

End With

Exit Sub
ErrorHandler:
    MsgBox "Error!"
End Sub
Was it helpful?

Solution

When ItemSend event fires, the message has not been submitted yet (you can set the Cancel parameter to true). The earliest you can see the message in the sent state is when the Items.ItemAdd event fires on the Sent Items folder.

Why not simply set the MailItem.SaveSentMessageFolder property? Outlook will automatically move the message after it is sent. The only limitation is that the folder must be in the same store where the message was created.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top