none
How do I prepend to the body of an email? RRS feed

  • Question

  • Hello, I built an plugin to write to the body of an email. It works but I need to write to the very top of the body and currently it's witting to the bottom when the user has a signature. Is there anyway to force it to write to the top line of the body?  Thanks, this is making me crazy.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;

    namespace writeToBodyOnSend
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
            }


            private void Application_ItemSend(object Item, ref bool Cancel)
            {
                // Code to run when item is being sent
                //string sMyAdditionalText = "PROMOTIONAL MATERIAL";
                string sMyAdditionalText = "<html><body><font size=1><h1>testint<h1><font size=1>PROMOTIONAL MATERIAL<font></a><br><br></body></html>";
                Outlook.MailItem mi = Item as Outlook.MailItem;
                //mi.HTMLBody += string.Concat(sMyAdditionalText);
                mi.HTMLBody = string.Concat(sMyAdditionalText);

            }


            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);
            }
            
            #endregion
        }
    }


    Saturday, September 21, 2013 6:56 PM

Answers

  • Hi,

    Since you just want to add a special sentence to the top of the mail body, I think you could change the code as followed and It should work.

    mi.HTMLBody = string.Concat(sMyAdditionalText) + mi.HTMLBody;
    //mi.HTMLBody += string.Concat(sMyAdditionalText);
    //mi.HTMLBody = string.Concat(sMyAdditionalText);

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Kevin P Moore Friday, September 27, 2013 3:09 AM
    Tuesday, September 24, 2013 10:56 AM
    Moderator

All replies

  • Hi,

    Since you just want to add a special sentence to the top of the mail body, I think you could change the code as followed and It should work.

    mi.HTMLBody = string.Concat(sMyAdditionalText) + mi.HTMLBody;
    //mi.HTMLBody += string.Concat(sMyAdditionalText);
    //mi.HTMLBody = string.Concat(sMyAdditionalText);

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Kevin P Moore Friday, September 27, 2013 3:09 AM
    Tuesday, September 24, 2013 10:56 AM
    Moderator
  • Luna, Thanks! I'm new at this as you can tell. We are just adding the strings in a different order. Easy.

    Friday, September 27, 2013 3:09 AM