none
Changing body of a forwarded mail item RRS feed

  • Question

  • Hi *,

    I'm writing a C++ Add-On and I have an Inspector wrapper around a new inspector opened as a result of the user forwarding a mail item. I'd like to replace the contents of this new email, changing the attachments and body. The attachments work as expected (I can add and remove attachments) but when trying to change the HTMLBody of the new mail item, for some reason, the original mail (the one being forwarded) is changed.

    Any hints would be appreciated.

    Cheers,
    Slavik

    Thursday, February 6, 2014 5:13 PM

Answers

  • Outlook 2007 and later use Word as the editor for everything, including HTML. It's not like Outlook 2003 and earlier where WordMail was optional.

    When are you checking for .IsWordMail? It should be after the first Activate() event fires on the Inspector, until then you only get a weak object reference that doesn't hydrate all the Inspector or Inspector.CurrentItem properties.


    Ken Slovak MVP - Outlook

    Friday, February 7, 2014 3:35 PM
    Moderator

All replies

  • Hi Slavik,

    You can use the Word object model for editing the body of messages. The WordEditor property of the Inspector class returns a instance of the Document class from the Word object model. The GetInspector method of the MailItem class returns an Inspector object that represents an inspector initialized to contain the specified item. For example:

    Sub InsertBodyTextInWordEditor() 
     Dim myItem As Outlook.MailItem 
     Dim myInspector As Outlook.Inspector 
     'You must add a reference to the Microsoft Word Object Library 
     'before this sample will compile 
     Dim wdDoc As Word.Document 
     Dim wdRange As Word.Range 
     
     On Error Resume Next 
     Set myItem = Application.CreateItem(olMailItem) 
     myItem.Subject = "Testing..." 
     myItem.Display 
     'GetInspector property returns Inspector 
     Set myInspector = myItem.GetInspector 
     'Obtain the Word.Document for the Inspector 
     Set wdDoc = myInspector.WordEditor 
     If Not (wdDoc Is Nothing) Then 
     'Use the Range object to insert text 
     Set wdRange = wdDoc.Range(0, wdDoc.Characters.Count) 
     wdRange.InsertAfter ("Hello world!") 
     End If 
    End Sub
    

    Thursday, February 6, 2014 5:26 PM
  • Hi Eugene, thanks a lot for your reply.

    Unfortunately, I cannot treat the item as Word.Document because the property for the Inspector.IsWordMail is false - the original email I'm trying to forward is an HTML email.

    PS - Outlook 2010 but would like to keep 2007 compatibility.

    Thanks much,
    Slavik

    Thursday, February 6, 2014 11:26 PM
  • Slavik,

    What code do you use for changing the HTMLBody property?

    What exactly is changed in the body? Could you please be more specific?

    Friday, February 7, 2014 6:47 AM
  • Outlook 2007 and later use Word as the editor for everything, including HTML. It's not like Outlook 2003 and earlier where WordMail was optional.

    When are you checking for .IsWordMail? It should be after the first Activate() event fires on the Inspector, until then you only get a weak object reference that doesn't hydrate all the Inspector or Inspector.CurrentItem properties.


    Ken Slovak MVP - Outlook

    Friday, February 7, 2014 3:35 PM
    Moderator
  • Ken, you were right, of course. I forgot I need to wait for the Activate() event to fire before accessing the Inspector props.

    Thanks much,
    Slavik

    Friday, February 21, 2014 3:26 AM