none
Outlook 2007 Macro Reply to E-mail Address From Received E-Mail RRS feed

  • Question

  • I have one code that replies to an email using one of my email templates, but does not put in the email address to the email I received.  That's the first one I will post.  And the next code I will post, replies to the email address of the email I received, but does not include my template....so what can I change in either one so it replies to the email using my template and sends to the email address that was from what I received?

    Sub Reply_Scripting()
     Dim origEmail As mailItem
     Dim replyEmail As mailItem
     Dim oRespond As outlook.mailItem
    Set origEmail = Application.ActiveWindow.Selection.Item(1)
     Set replyEmail = Application.CreateItemFromTemplate("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Good Morning Follow-Up Marketing to E-Mail Contacts.oft ")

    replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody


     replyEmail.Display

     End Sub

    Public Sub ReplyWithHTML()
     Dim oMail As outlook.mailItem
     Dim oFSO
     Dim oFS
      If Application.ActiveExplorer.Selection.Count Then
      If TypeOf Application.ActiveExplorer.Selection(1) Is outlook.mailItem Then
      Set oMail = Application.ActiveExplorer.Selection(1).Reply
     
      oMail.Display
      End If
      End If
     End Sub


    • Edited by lmseaz Friday, May 30, 2014 9:58 PM
    Friday, May 30, 2014 9:52 PM

Answers

  • Hello Imseaz,

    It looks like you need to add recipients to the just created message using a template. The Recipients property of the MailItem class returns an instance of the corresponding class which provides the Add method. It creates a new recipient in the Recipients collection. You just need to pass a string representing the display name, the alias, or the full SMTP e-mail address of the recipient. So, you can get the required info in the item - Application.ActiveExplorer.Selection(1) on which you want to reply. 

    Set myRecipient = myItem.Recipients.Add("Dan Wilson") 

    where Dan Wilson is the name of sender from the oMail item (according to your code).  

    Saturday, May 31, 2014 12:31 PM

All replies

  • Hello Imseaz,

    It looks like you need to add recipients to the just created message using a template. The Recipients property of the MailItem class returns an instance of the corresponding class which provides the Add method. It creates a new recipient in the Recipients collection. You just need to pass a string representing the display name, the alias, or the full SMTP e-mail address of the recipient. So, you can get the required info in the item - Application.ActiveExplorer.Selection(1) on which you want to reply. 

    Set myRecipient = myItem.Recipients.Add("Dan Wilson") 

    where Dan Wilson is the name of sender from the oMail item (according to your code).  

    Saturday, May 31, 2014 12:31 PM
  • As to the first code I posted, per another person's help in this area, I added the following before the display and it does it......hope all can use this when they need to!!

    replyEmail.To = origEmail.SenderEmailAddress

    Saturday, May 31, 2014 10:36 PM
  • Hello Imseaz,

    Here is what MSDN states for the To property of the MailItem class:

    Returns or sets a semicolon-delimited String list of display names for the To recipients for the Outlook item. This property contains the display names only.

    The Recipients collection should be used to modify this property.

    Sunday, June 1, 2014 11:50 AM