none
_MailAutoSig Bookmark missing (Outlook 2010)

    Question

  • I wrote an addin a while back for Outlook that adds/removes an optional tagline below the signature in an outlook message.  This add-in works with no issues.

    I'm writing a second add-in that needs to potentially add information below that (whether or not the optional signature is there) and am again referencing the _MailAutoSig bookmark from the Word editor.  The issue I'm running into is that this bookmark no longer seems to appear, nor does the bookmark from my other add-in.

    One difference in the two pieces of code below is that the first one has the MailItem being converted from an object passed by ItemSend

    Here is the code from what I am currently writing:

            Word.Document toMsg = msg.GetInspector.WordEditor as Word.Document;
    
          foreach (Word.Bookmark b in toMsg.Bookmarks)
            Debug.Print(b.ToString());
    
          Word.Range r_toMsg;
    
          try
          {
            string oBookmark = "_MailAutoSig"; // Outlook internal bookmark for location of the e-mail signature`
            object oBookmarkObj = oBookmark;
            if (toMsg.Bookmarks.Exists(oBookmark) == true)
              Debug.Print("sigbookmark");
            r_toMsg = toMsg.Bookmarks.get_Item(ref oBookmarkObj).Range;
          }
          catch
          {
            string oOffsiteBookmark = "OffsiteBookmark";
            object oOffsiteBookmarkObj = oOffsiteBookmark;
    
            if (toMsg.Bookmarks.Exists(oOffsiteBookmark) == true) // if the custom bookmark exists, remove it
              Debug.Print("offsite bookmark");
          }
          finally
          {
            r_toMsg = toMsg.Range(missing,missing);
          }
    
    
    
    and here is code from my working add-in:

       
    void InsertOffsiteSig(Outlook.MailItem oMsg)
      {
        object oBookmarkName = "_MailAutoSig"; // Outlook internal bookmark for location of the e-mail signature
        string oOffsiteBookmark = "OffsiteBookmark"; // bookmark to be created in Outlook for the Offsite tagline
        object oOffsiteBookmarkObj = oOffsiteBookmark;
    
        Word.Document SigDoc = oMsg.GetInspector.WordEditor as Word.Document; // edit the message using Word
    
        string bf = oMsg.BodyFormat.ToString(); // determine the message body format (text, html, rtf)
    
        // Go to the e-mail signature bookmark, then set the cursor to the very end of the range.
        // This is where we will insert/remove our tagline, and the start of the new range of text
    
        Word.Range r = SigDoc.Bookmarks.get_Item(ref oBookmarkName).Range;
        object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
    
        r.Collapse(ref collapseEnd);
    
        string[] taglines = GetRssItem(); // Get tagline information from the RSS XML file and place into an array
    
        
        // Loop through the array and insert each line of text separated by a newline
    
        foreach (string taglineText in taglines)
          r.InsertAfter(taglineText + "\n");
        r.InsertAfter("\n");
    
        // Add formatting to HTML/RTF messages
    
        if (bf != "olFormatPlain" && bf != "olFormatUnspecified")
        {
          SigDoc.Hyperlinks.Add(r, taglines[2]); // turn the link text into a hyperlink
          r.Font.Underline = 0; // remove the hyperlink underline
          r.Font.Color = Word.WdColor.wdColorGray45; // change all text to Gray45
          r.Font.Size = 8; // Change the font size to 8 point
          r.Font.Name = "Arial"; // Change the font to Arial
        }
    
        r.NoProofing = -1; // turn off spelling/grammar check for this range of text
        
        object range1 = r;
        SigDoc.Bookmarks.Add(oOffsiteBookmark, ref range1); // define this range as our custom bookmark
    
    
        if (bf != "olFormatPlain" && bf != "olFormatUnspecified")
        {
          // Make the first line BOLD only for HTML/RTF messages
    
          Word.Find f = r.Find;
          f.Text = taglines[0];
          f.MatchWholeWord = true;
          f.Execute();
          while (f.Found)
          {
            r.Font.Bold = -1;
            f.Execute();
          }
        }
        else
        {
          // otherwise turn the plain text hyperlink into an active hyperlink
          // this is done here instead of above due to the extra formatting needed for HTML/RTF text
    
          Word.Find f = r.Find;
      
    
          f.Text = taglines[2];
            f.MatchWholeWord = true;
            f.Execute();
            SigDoc.Hyperlinks.Add(r, taglines[2]);
          }
          r.NoProofing = -1; // disable spelling/grammar checking on the updated range
          r.Collapse(collapseEnd);
      }
    


      
    Tuesday, May 17, 2011 3:57 PM

Answers

All replies

  • Hi lwgapnitsky,

     

    Thanks for posting in the MSDN Forum.

     

    Would you please clarify some questions?

     

    1.       Is the second snippet used in the ItemSend method?

    2.       Where you add the “_MailAutoSig” book mark in to your mail’s body?

     

    As far as I know the “_MailAutoSig” is a customized book mark, new mail item will never have any bookmarks in its body, but I can’t find the place where you insert the particular book into mail body.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 20, 2011 3:46 AM
    Moderator
  • Tony,

    In response to your questions:

    1:  No.  It is called on the active inspector while the message (new, reply, forwarrd, etc.) is being composed.

    2:  I am not creating the bookmark, just searching for it.

    "_MailAutoSig" exists in new composed messages, which is how my original add-in works, but I am starting to see that this bookmark may be removed once the ItemSend is called, thereby possibly making my question moot.


    Thank you,

    Larry

    Friday, May 20, 2011 12:38 PM
  • Hi Larry,

     

    I created an add-in to add a mark to the mail body when I’m composing my mail and sent it to my other account. And I can find the particular bookmark when I received the mail. I use Outlook 2010 32-bit created add-in via VSTO 4.0. Would you tell me your Outlook version?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 5:07 AM
    Moderator
  • Outlook 2010 32-bit. The issue is post-send, not pre-send. The latter I have working properly. I've decided to move forward and abandon this for now as my project has other needs.
    Wednesday, May 25, 2011 2:16 PM
  • Hi lwgapnitsky,

     

    I think I don’t understand the mean of “post-send” and “pre-send”. Would you please clarify these?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 26, 2011 11:29 AM
    Moderator
  • I am having the same issue.  "_MailAutoSig" is a Microsoft bookmark that is created when Outlook inserts a signature.  The following article describes this bookmark: http://msdn.microsoft.com/en-us/library/dd492012(v=office.12).aspx#Outlook2007ProgrammingCh17_WorkingWithOutlookSignatures

    From what I can tell, the HTML for the signature has been converted from "Word HTML" to regular HTML before the ItemSend() event is fired.  This removes the bookmarks and any other marking that you could construe as a signature.


    Monday, July 18, 2011 10:15 PM