This macro will reply to the person who sent the message. It includes the original message, any text entered by in the macro, plus the content of the template.
Because this is a run a script rule, all messages meeting the condition will be replied to, unlike the autoreply rule which is one message per Outlook session.
If you want to include the original subject, use (or add) item.subject to the .Subject field, otherwise, this should have most of the bases covered and point you in the right direction for things I didn't include. Remove the parts you don't need and you should be good to go....
Keep in mind that the original message is Item, from Item As Outlook.MailItem. oRespond is the message you are sending back. You need to use the Item fields if you want to include fields from the original message in the response.
Sub AutoReplywithTemplate(Item As Outlook.MailItem) Dim oRespond As Outlook.MailItem ' Use this for a real reply ' Set oRespond = Item.Reply ' This sends a response back using a template Set oRespond = Application.CreateItemFromTemplate("C:\path\to\template.oft") With oRespond .Recipients.Add Item.SenderEmailAddress .Subject = "Your Subject Goes Here" .HTMLBody = "Your reply text goes here." & vbCrLf & _ "---- original body below ---" & vbCrLf & _ Item.HTMLBody & vbCrLf & _ "---- Template body below ---" & _ vbCrLf & oRespond.HTMLBody ' includes the original message as an attachment .Attachments.Add Item ' use this for testing, change to .send once you have it working as desired .Display End With Set oRespond = Nothing End Sub
Reply to a web form generated message
If you want to reply to a person who fills out a web form but the email that is generated is from a generic emai8l address, not their address, you can use RegEx to get the address.
Sub SendNew(Item As Outlook.MailItem) Dim Reg1 As Object Dim M1 As Object Dim M As Object Dim strAddress As String Set Reg1 = CreateObject("VBScript.RegExp") With Reg1 .Pattern = "(([\w-\.]*\@[\w-\.]*)\s*)" .IgnoreCase = True .Global = False End With If Reg1.Test(Item.Body) Then Set M1 = Reg1.Execute(Item.Body) For Each M In M1 strAddress = M.SubMatches(1) Next End If Dim objMsg As MailItem Set objMsg = Application.CreateItemFromTemplate("C:\path\to\template.oft") objMsg.Recipients.Add strAddress ' Copy the original message subject objMsg.Subject = "Thanks: " & Item.Subject ' use for testing objMsg.display ' objMsg.Send End Sub
More Run a Script Samples:
- Autoaccept a Meeting Request using Rules
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Delete older messages when a new message arrives
- Forward meeting details to another address
- How to Change the Font used for Outlook's RSS Feeds
- Keep Canceled Meetings on Outlook's Calendar
- Move messages CC'd to an address
- Outlook AutoReplies: One script, many responses
- Outlook's Rules and Alerts: Run a Script
- Process messages received on a day of the week
- Read Outlook Messages using Plain Text
- Run a Script Rule: Change Subject then Forward Message
- Run a script rule: Reply to a message
- Run a Script Rule: Send a new message when a message arrives
- Sort messages by Sender domain
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments