SentOnBehalfOfName will not work RRS feed

  • Question

  • Her is what I try to do:

    namespace OutlookAddIn_changeSender
        public partial class ThisAddIn

       void Application_ItemSend(object Item, ref bool Cancel) {
        Outlook.MailItem aMail = Item as Outlook.MailItem;
        if (aMail != null)    {
          aMail.SentOnBehalfOfName = "firstname.secondname@companyname.de";
         // aMail.SendUsingAccount = Application.Session.Accounts.?????????;
         aMail.Body = aMail.Body + ">>>" + aMail.SendUsingAccount.SmtpAddress.ToString();


       private void ThisAddIn_Startup(object sender, System.EventArgs e) {
        // attach to the Item Send Event
        Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);


          private void ThisAddIn_Shutdown(object sender, System.EventArgs e)      {      }

            #region VSTO generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);


    We use Exchange and the user has two Exchange-accounts open in his Outlook 2010.

    His own account and a account who is shared with another user in the same Company.

    My problem happens when the user answer a mail from the shared-account. This mail is send out with the e-mail-adress of the account, which is only a dummy company-intern e-mail-adr. If the recipient of such a mail just click on answer the dummy adress is used and the result is a error.

    This ist the reson for above "outlook add in"

    But it does not work. I can see that the event happens and the function is called: this line shows me that

         aMail.Body = aMail.Body + ">>>" + aMail.SendUsingAccount.SmtpAddress.ToString();

    But the Sender is not changed. What is wrong what must I do?

    Thx a lot!

    Michael Tischer

    Friday, May 9, 2014 6:40 AM


All replies

  • Hello Michael,

    It looks like the ItemSend event is too late for setting the SentOnBehalfOfName property. Try setting the property before the Send method is called or when a user clicks the Send button (intercept the Ribbon UI buttons).

    Friday, May 9, 2014 8:55 AM
  • Hi Eugene,
    best thanks for your answer. That is a good idea, it makes sens for me.
    But I have no concept how to intercept the UI "Send" button. Do you have a hint for me?

    Michael Tischer

    Friday, May 9, 2014 10:02 AM
  • Hi Michael,

    You can read about this in the Temporarily Repurpose Commands on the Office Fluent Ribbon article.

    Friday, May 9, 2014 11:35 AM
  • Thx for this, but the given URL targets a blank side.
    I search the internet now 2 days long but i am not able to find a small example of how I can "repurpose a command" in outlook 2010 or 2013. Do you have another tip for me?

    Michael Tischer

    Tuesday, May 13, 2014 7:57 AM
  • Michael,

    Try to scroll down the page. It looks like something wrong with the HTML markup. It describes exactly what you are looking for.

    Tuesday, May 13, 2014 12:01 PM
  • Yes thx, now I found this good example, but I am looking for a example how to this this with a "add in" for Outlook 2010 or 2013. Do you have a idea?

    Michael Tischer

    Friday, May 16, 2014 12:06 PM
  • The Ribbon UI XML markup is common for all types of applications (VBA or add-in). See How to: Customize the Office Fluent Ribbon by Using a Managed COM Add-in .

    Friday, May 16, 2014 1:14 PM