locked
Add to email reply RRS feed

  • Question

  • I have developed an Outlook addin that adds a corporate signature based on active directory attributes when creating a new email. When the addins loads it puts all of the necessary signature information into an HTML file which the inspector then loads.

    Now users want to be able to add the signature to replys as well.

    Here is how the application adds the signature to the new email:

    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
            {
    
                Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
                if (mailItem != null)
                {
                    if (mailItem.EntryID == null)
                    {
                        if (mailItem.Body == null)
                        {
    
                            StringBuilder bodyEmail = new StringBuilder();
                            using (StreamReader HTMLSig = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures\\AutoSignature.html"))
                            {
                                string line;
                                while ((line = HTMLSig.ReadLine()) != null)
                                {
                                    bodyEmail.AppendLine(line); // Add to list.
                                }
                            }
                            
                            mailItem.HTMLBody = bodyEmail.ToString();
                        }
                    }               
                }

    How can I now add this signature to a reply? Ive tried the following but it adds the signature before the email information (To, From, Date etc.) and then when I exit the reply it modifies the message and saves it with the signature in.

           void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
            {
    
                Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
                if (mailItem != null)
                {
                    if (mailItem.EntryID == null)
                    {
                        if (mailItem.Body == null)
                        {
    
                            StringBuilder bodyEmail = new StringBuilder();
                            using (StreamReader HTMLSig = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures\\AutoSignature.html"))
                            {
                                string line;
                                while ((line = HTMLSig.ReadLine()) != null)
                                {
                                    bodyEmail.AppendLine(line); // Add to list.
                                }
                            }
    
                            mailItem.HTMLBody = bodyEmail.ToString();
                        }
                    }
    
                    else
                    {
    
                        StringBuilder bodyEmail = new StringBuilder();
                        using (StreamReader HTMLSig = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures\\AutoSignature.html"))
                        {
                            string line;
                            while ((line = HTMLSig.ReadLine()) != null)
                            {
                                bodyEmail.AppendLine(line); // Add to list.
                            }
                        }
    
                        mailItem.HTMLBody = bodyEmail.ToString() + mailItem.HTMLBody;
                    }
                }
            }

    Can anybody advise me on this?

    Friday, August 3, 2012 10:23 AM

Answers

  • this approach will not fly - on reply you have to find specific bookmark in mail (using WordAPI) named  _MailOriginal or if you want to do it by string replace find element that has style like this:  style='mso-bookmark:_MailOriginal' and insert your data before it.
    • Marked as answer by Quist Zhang Monday, August 6, 2012 10:41 AM
    Friday, August 3, 2012 12:59 PM
  • word is used as mail editor from outlook 2007 onward, whenever you like it or not.
    • Marked as answer by Quist Zhang Monday, August 6, 2012 10:41 AM
    Friday, August 3, 2012 2:57 PM

All replies

  • this approach will not fly - on reply you have to find specific bookmark in mail (using WordAPI) named  _MailOriginal or if you want to do it by string replace find element that has style like this:  style='mso-bookmark:_MailOriginal' and insert your data before it.
    • Marked as answer by Quist Zhang Monday, August 6, 2012 10:41 AM
    Friday, August 3, 2012 12:59 PM
  • Presumably that would only work if you are using Word as the email editor. We dont, we use Outlook because Word is "not very good"
    Friday, August 3, 2012 1:19 PM
  • word is used as mail editor from outlook 2007 onward, whenever you like it or not.
    • Marked as answer by Quist Zhang Monday, August 6, 2012 10:41 AM
    Friday, August 3, 2012 2:57 PM
  • Aaah I did not know that. 

    OK, so now i need to work out how to do what you suggest. Thanks for the nudge in the right direction.

    Friday, August 3, 2012 3:03 PM