none
When the sender of the mail item has been changed. RRS feed

  • Question

  • I am creating an add-in using VB .Net to process mail items when the send button is clicked. There are outlooks in which multiple accounts are set in the Outlook that the add-in is going to be installed.
    If the send button is clicked after the sender has been changed in the new mail window, it seems to be processed by the account before change. For example, mail items remain in the outbox of the account before change.

    Is there a way to make it work with the account set at the time of sending?

    Monday, January 23, 2017 11:46 AM

Answers

  • Hi,

    What is your office version? I failed to reproduce your issue with Office 2016. The mail would be successfully sent and the duplicated item would be deleted.

    I suggest you unload other add-ins and add line MsgBox(item.SendUsingAccount.SmtpAddress)  or MsgBox(item.SendUsingAccount.DisplayName) before Cancel=True to check current sender when sending.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by giro011 Wednesday, January 25, 2017 10:37 AM
    Wednesday, January 25, 2017 8:29 AM
    Moderator

All replies

  • Hello,

    > If the send button is clicked after the sender has been changed in the new mail window, it seems to be processed by the account before change.

    That is not true. Did you have a chance to check out the sender in the sent email (see the Sent Items folder)?

    If you need to change the sender after the Send button is clicked you may consider handling the ItemSend event which allows to cancel the default action and do whatever you need with the item. After you can call the Send method for submitting a modified item anew.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Eugene Astafiev Wednesday, January 25, 2017 10:42 AM
    Monday, January 23, 2017 1:35 PM
  • Hi,

    As you said, once the sender has been changed, I confirmed that it will be sent out under the changed account.

    I am currently doing the processing as below.
    With the changed sender's account, not only the mail I want to send but also the original mail item I want to delete will be sent. Furthermore, the original mail item will remain in outbox of the original account.

    I am considering deleting mail items for each account object or store object, but I have not succeeded yet.

    Private Sub Application_ItemSend(ByVal item As MailItem, ByRef Cancel As Boolean) Handles Application.ItemSend
            Cancel = True
            Dim toTemplate As MailItem = item.Copy
            Dim toSend As MailItem = item.Copy
            toTemplate.SaveAs("E:\test.oft", OlSaveAsType.olTemplate)
            toSend.Send()
            Me.Application.ActiveInspector.Close(OlInspectorClose.olDiscard)
            Dim myNamespace As [NameSpace] = Application.GetNamespace("MAPI")
            Dim myFolder As Folder = myNamespace.GetDefaultFolder(OlDefaultFolders.olFolderOutbox)
            Dim MailItem As MailItem = myFolder.Items(1)
            mailItem.Delete()
    End Sub



    • Edited by giro011 Tuesday, January 24, 2017 3:07 AM
    Tuesday, January 24, 2017 2:32 AM
  • Hi,

    What is your office version? I failed to reproduce your issue with Office 2016. The mail would be successfully sent and the duplicated item would be deleted.

    I suggest you unload other add-ins and add line MsgBox(item.SendUsingAccount.SmtpAddress)  or MsgBox(item.SendUsingAccount.DisplayName) before Cancel=True to check current sender when sending.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by giro011 Wednesday, January 25, 2017 10:37 AM
    Wednesday, January 25, 2017 8:29 AM
    Moderator
  • I found that the problem was occurring because I complicated the code. There was no problem at all if it was the code you presented.

    Wednesday, January 25, 2017 10:37 AM