none
On click on “Send” button on message, we need to save sent mail in a dummy folder as a message, not as a draft mail RRS feed

  • Question

  • Environment: -

    OS:  Windows 7 32 bit

    MSOffice: - MS Office 2007

    Development Type: - Shared Outlook AddIns

    IDE: - Visual Studio 2008

    .

    Application Description: - We have developed AddIns Application for Outlook, in that when user compose a mail and click on send button; we save mail in some dummy folder.

    .

    Requirement: - After composing new message: On click on send button, if mail has sent successfully, then only we have to save message in some dummy folder. And also message must be saved as message, not as a draft.

    .

    Issue Facing: - Mail is saving as a draft in dummy folder. And, also we are not sure that it has sent successfully.

    .

    Code snippet for reference: -

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OutlookApplication.ItemSend

    Try

       Dim documentPathName As String = ""

       Dim SentMailItemObject As Outlook.MailItem

       SentMailItemObject = CType(Item, Outlook.MailItem)

      documentPathName = "C:\Temp\AddIns\" & SentMailItemObject.Subject & ".msg"

      SentMailItemObject.SaveAs(documentPathName)

     Catch ex As Exception

         MsgBox(ex.Message, MsgBoxStyle.Information)

     End Try

    Kindly assist us for achieving the required feature. I will be really thankful.



    • Edited by S.P Singh Thursday, April 9, 2015 3:36 PM Formatting
    Thursday, April 9, 2015 3:35 PM

Answers

  • The Add method accepts the following required parameters:

    Name

    Required

    String

    The name of the property. The maximum length is 64 characters. The characters, '[', ']', '_' and '#', are not permitted in the name.

    Type

    Required

    OlUserPropertyType

    The type of the new property.

    You need to specify the OlUserPropertyType value as a second parameter.

    • Marked as answer by S.P Singh Friday, April 10, 2015 5:37 PM
    Thursday, April 9, 2015 6:06 PM
  • You can add a user property (MailItem.UserProperties.Add), but that would cause the message to be sent in the RTF (TNEF) format unless the UseTnef property (DASL name `http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8582000B`) is explicitly set to false.

    You can set a named MAPI property using PropertyAccessor.SetProperty - just pick your custom GUID and property name. E.g.

    SentMailItemObject.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{3ADE3813-37A9-49C9-AD84-D49C8FF5D660}/MyOwnProp", "SomeValue")


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!




    Thursday, April 9, 2015 9:22 PM

All replies

  • Instead of using Application.ItemSend event, use Items.ItemAdd event on the Sent Items folder - by that time the message will be in the sent state with all the sender related properties populated.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, April 9, 2015 3:39 PM
  • You need to handle the ItemAdd event of the Sent Emails folder. It is fired when one or more items are added to the specified collection. 

    Also the MailItem class provides SaveSentMessageFolder property which allows to set a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent. So you can specify any folder you need to save the item.

    Thursday, April 9, 2015 3:39 PM
  • Hi Sir,

    Kindly let me know following, when user will click on send button, and suppose message has sent successfully, and then an item will be added in sent item folder.

    Whether mail adds in inbox or sent item or any other folder, control will come in ItemAdd method. How will I know, which was sent item mail, which we have sent recently.

     



    • Edited by S.P Singh Thursday, April 9, 2015 5:10 PM Formatting
    Thursday, April 9, 2015 5:05 PM
  • In the ItemSend event handler (or anywhere else) you can add a user property to mark the item for futher processing in the ItemAdd event.

    In the ItemAdd event handler you can check out whether a user property exists or not.

     
    Thursday, April 9, 2015 5:07 PM
  • Hi Sir,

    How can I add user property in mail item? Because mail is composing using Outlook/File/New option, then we click on send button.

    We only receive Mail Item object reference. Can we add user property in that?


    Thursday, April 9, 2015 5:20 PM
  • You can use the ItemSend event handler for adding a user property.
    Thursday, April 9, 2015 5:21 PM
  • Hi Sir,

    ItemSend, we are already using.

    Code snippet for reference: -

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)Handles OutlookApplication.ItemSend

    Try

       

       Dim SentMailItemObject As Outlook.MailItem

       SentMailItemObject = CType(Item, Outlook.MailItem)

     

    Can we add here User property in Mail Object reference

     Catch ex As Exception

         MsgBox(ex.Message, MsgBoxStyle.Information)

     End Try

    End Sub


    • Edited by S.P Singh Thursday, April 9, 2015 5:30 PM
    Thursday, April 9, 2015 5:29 PM
  • Where do you add a user property?
    Thursday, April 9, 2015 5:30 PM
  • Hi Sir,

    Code snippet for reference: -

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)Handles OutlookApplication.ItemSend

    Try

       

       Dim SentMailItemObject As Outlook.MailItem

       SentMailItemObject = CType(Item, Outlook.MailItem)

     

    Can we add here User property in Mail Object Reference?

     Catch ex As Exception

         MsgBox(ex.Message, MsgBoxStyle.Information)

     End Try

    End Sub

    Thursday, April 9, 2015 5:32 PM
  • Yes, you can add a user property instead of the line marked with red. Use the UserProperties property of the MailItem class for adding a new user property.
    Thursday, April 9, 2015 5:36 PM
  • Hi Sir,

              I have added like this: 

    Code snippet for reference: -

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)Handles OutlookApplication.ItemSend

    Try

       

       Dim SentMailItemObject As Outlook.MailItem

       SentMailItemObject = CType(Item, Outlook.MailItem)

           SentMailItemObject.UserProperties.Add("MailType", “AddInsMail”);

     Catch ex As Exception

         MsgBox(ex.Message, MsgBoxStyle.Information)

     End Try

    End Sub

    And in ItemAdd, I will read all added mails and check if mail item is having this property. If mail is having set property, then I will dump it to some dummy folder.

    Thursday, April 9, 2015 5:41 PM
  • The Add method accepts the following required parameters:

    Name

    Required

    String

    The name of the property. The maximum length is 64 characters. The characters, '[', ']', '_' and '#', are not permitted in the name.

    Type

    Required

    OlUserPropertyType

    The type of the new property.

    You need to specify the OlUserPropertyType value as a second parameter.

    • Marked as answer by S.P Singh Friday, April 10, 2015 5:37 PM
    Thursday, April 9, 2015 6:06 PM
  • You can add a user property (MailItem.UserProperties.Add), but that would cause the message to be sent in the RTF (TNEF) format unless the UseTnef property (DASL name `http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8582000B`) is explicitly set to false.

    You can set a named MAPI property using PropertyAccessor.SetProperty - just pick your custom GUID and property name. E.g.

    SentMailItemObject.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{3ADE3813-37A9-49C9-AD84-D49C8FF5D660}/MyOwnProp", "SomeValue")


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!




    Thursday, April 9, 2015 9:22 PM