none
Include Original Text Message when AutoReply RRS feed

  • Question

  • I set an AutoReply rule using a template. The problem is that the reply does not add the original message. 

    does anyone have an idea what script VBScript should i add in order to add the original message in the reply?

    Tried with this, but it does not work

    Sub AutoReply(Item As Outlook.MailItem)
        Dim olkReply As Outlook.MailItem
        Set olkReply = Item.Reply
        With olkReply
            'Change the subject on the next line as desired'
            .Subject = "Your Subject Goes Here"
            'Change the body as desired'
            .HTMLBody = "Your reply text goes here.<bt><br>" & olkReply.HTMLBody
            .Send
        End With
        Set olkReply = Nothing
    End Sub

    Thank you! 


    • Edited by BKBfromBG Monday, November 28, 2016 9:08 PM
    Monday, November 28, 2016 3:44 PM

Answers

  • Hi MigrationUser 1,

    you had mentioned that," I suppose i should add a script which would keep the original message. I am not sure if the script should only copy the orignal message."

    here you had mentioned that with the above mentioned code you are able to send the template.

    but you also want to include the mail body that you had received in mail. so that when you reply and send mail.

    the previous mail body + your template will be send.

    so that user can know in which matter you replied him back.

    like below is an original mail.

    then I run the code mentioned below.

    Sub olReply()
     Dim objOL As Outlook.Application
     Dim objMsg As Outlook.MailItem
     Dim oReply As Outlook.MailItem
     Dim objSelection As Outlook.Selection
     Set objOL = Application
     Set objSelection = objOL.ActiveExplorer.Selection
     For Each objMsg In objSelection
      Set oReply = objMsg.Reply
      oReply.Body = "test" & objMsg.Body
      oReply.Display
     Next
     Set objMsg = Nothing
     Set objSelection = Nothing
     Set objOL = Nothing
     Set oReply = Nothing
    End Sub

    I get output below.

    This is just a demo code to give you an example. you can modify it as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 29, 2016 3:47 AM
    Moderator
  • Then you need to modify the HTML message body correctly. As I wrote earlier, the following line of code doesn't make any sense because you get not a well formed HTML markup:

    >  .HTMLBody = "Your reply text goes here.<bt><br>" & olkReply.HTMLBody

    Instead, you need to find the <body> tag and insert your text which should be shown in the message.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Tuesday, November 29, 2016 2:15 PM
  • Hi BKBfromBG,

    are you able to select the above mentioned macro code when you select the script?

    if yes then try to turn on the rule and check whether it is adding the original body or not.

    I find the link that may help you.

    you can create an event that will execute when you click on Reply button.

    here below is a demo code.

    Option Explicit
    Private WithEvents oExpl As Explorer
    Private WithEvents oItem As MailItem
    Private bDiscardEvents As Boolean
    'http://slipstick.me/44b0w
     
    Private Sub Application_Startup()
       Set oExpl = Application.ActiveExplorer
       bDiscardEvents = False
    End Sub
     
    Private Sub oExpl_SelectionChange()
       On Error Resume Next
       Set oItem = oExpl.Selection.Item(1)
    End Sub
     
    ' Reply
    Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
      
    'you need to write your code here
    End Sub
     

    Reference:

    VBA Sample: Do Something When Reply is Clicked

    Run a script rule: Reply to a message

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Wednesday, November 30, 2016 12:41 AM
    Moderator
  • You cannot concatenate two HTML strings and expect a valid HTML string back. Reda the existing HTML body (olkReply.HTMLBody), find the position of the "<body" substring, find the position of the next ">" character (this way you can take care of the body tag with attributes), then insert your extra HTML text at that position.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Tuesday, November 29, 2016 4:53 AM

All replies

  • Hello,

    When you call the Reply method of the MailItem class, the original message body is already included in the reply. You just need to append your own text to message body. So, the following line of code doesn't make any sense:

    >  .HTMLBody = "Your reply text goes here.<bt><br>" & olkReply.HTMLBody

    Instead, you need to insert your own text into the <body>...</body> tags. Or just use the Word editor to make the required changes.

    The Outlook object model provides three main ways for working with item bodies:

    1. Body - a string representing the clear-text body of the Outlook item.
    2. HTMLBody - a string representing the HTML body of the specified item.
    3. Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.

    You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the message body.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, November 28, 2016 6:42 PM
  • Hi MigrationUser 1,

    you had mentioned that," I suppose i should add a script which would keep the original message. I am not sure if the script should only copy the orignal message."

    here you had mentioned that with the above mentioned code you are able to send the template.

    but you also want to include the mail body that you had received in mail. so that when you reply and send mail.

    the previous mail body + your template will be send.

    so that user can know in which matter you replied him back.

    like below is an original mail.

    then I run the code mentioned below.

    Sub olReply()
     Dim objOL As Outlook.Application
     Dim objMsg As Outlook.MailItem
     Dim oReply As Outlook.MailItem
     Dim objSelection As Outlook.Selection
     Set objOL = Application
     Set objSelection = objOL.ActiveExplorer.Selection
     For Each objMsg In objSelection
      Set oReply = objMsg.Reply
      oReply.Body = "test" & objMsg.Body
      oReply.Display
     Next
     Set objMsg = Nothing
     Set objSelection = Nothing
     Set objOL = Nothing
     Set oReply = Nothing
    End Sub

    I get output below.

    This is just a demo code to give you an example. you can modify it as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 29, 2016 3:47 AM
    Moderator
  • You cannot concatenate two HTML strings and expect a valid HTML string back. Reda the existing HTML body (olkReply.HTMLBody), find the position of the "<body" substring, find the position of the next ">" character (this way you can take care of the body tag with attributes), then insert your extra HTML text at that position.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Tuesday, November 29, 2016 4:53 AM
  • HI deepak,

    just can't make this work. Do i do it right?

    Tuesday, November 29, 2016 10:49 AM
  • hi I am not sure i explain correctly. And i cannot attach a pic. I iwill describe this in steps.

    1. create a rule in Outlook MS office 365 > Step  - "Which Condition do you want to check?" - I select no condition and go "next" ( I click yes when asked "This Rule will be applied to every message you receive. Is this correct?") > Step - Select action - I chose "reply using a specific template"  and I add a saved template > Step - Select exceptions if necessary - I select nothing > on the last step I do not run the rule and i do not turn it on.

    At this stage it works perfectly. When i select a folder and run the rule for this specific folder, the rule replies with the template, but the message sent includes only the template and it excludes the original text message. ( although when manual reply original message text is included).

    At this stage i started googlling for scripts and opened the topic.

    I thought that either i should add a script in the Step "Select action". A script, which would "include original message text"  and work in combination with "reply using a specific template"

    OR

    in the Step "Select action" I should untick "reply using a specific template" and add a script, which would do both - "include original message text" and "reply using a specific template".

    So please tell me how can i make this work and what should be the script.

    Tuesday, November 29, 2016 10:51 AM
  • Then you need to modify the HTML message body correctly. As I wrote earlier, the following line of code doesn't make any sense because you get not a well formed HTML markup:

    >  .HTMLBody = "Your reply text goes here.<bt><br>" & olkReply.HTMLBody

    Instead, you need to find the <body> tag and insert your text which should be shown in the message.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Tuesday, November 29, 2016 2:15 PM
  • Hi BKBfromBG,

    are you able to select the above mentioned macro code when you select the script?

    if yes then try to turn on the rule and check whether it is adding the original body or not.

    I find the link that may help you.

    you can create an event that will execute when you click on Reply button.

    here below is a demo code.

    Option Explicit
    Private WithEvents oExpl As Explorer
    Private WithEvents oItem As MailItem
    Private bDiscardEvents As Boolean
    'http://slipstick.me/44b0w
     
    Private Sub Application_Startup()
       Set oExpl = Application.ActiveExplorer
       bDiscardEvents = False
    End Sub
     
    Private Sub oExpl_SelectionChange()
       On Error Resume Next
       Set oItem = oExpl.Selection.Item(1)
    End Sub
     
    ' Reply
    Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
      
    'you need to write your code here
    End Sub
     

    Reference:

    VBA Sample: Do Something When Reply is Clicked

    Run a script rule: Reply to a message

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by BKBfromBG Thursday, December 1, 2016 1:06 PM
    Wednesday, November 30, 2016 12:41 AM
    Moderator
  • Thank you All. It finally worked. I don't know where my eyes were.

    Thank you!

    Thursday, December 1, 2016 1:07 PM