How to use a Run a Script rule to have Microsoft Outlook automatically send a new email message using a template, to a new email addresses when a message meeting specific conditions arrives. I also have a version of the script that sends a new message with the body of the message that triggered the rule to another person. (To avoid including the Reply header in the body).
To use, open the VBA Editor and paste the code into ThisOutlookSession. Create a Run a Script rule, selecting this rule.
When you create the template, do not include a signature. Outlook will add the signature when the message is sent. To test the rule without sending messages, change objMsg = Send to ojbMsg = Display. This will open the message form instead of sending it.
New message using a template
Sub SendNew(Item As Outlook.MailItem) Dim objMsg As MailItem Set objMsg = Application.CreateItemFromTemplate("C:\path\to\test-rule.oft") ' If the address you want to send to is not saved in the template, ' set the addresses here 'objMsg.Recipients.Add "firstname.lastname@example.org" objMsg.Send End Sub
To reply to the sender using a template
This script could be used for an Out of Office style reply. Using this method will send a reply with every message that meets the condition of the rule.
Sub SendNew(Item As Outlook.MailItem) Dim objMsg As MailItem Set objMsg = Application.CreateItemFromTemplate("C:\path\to\test-rule.oft") objMsg.Recipients.Add Item.SenderEmailAddress ' Copy the original message subject objMsg.Subject = "Attn: " & Item.Subject objMsg.Send End Sub
To Forward the message body to another address
This version of the script sends a new message containing the body of the received message. (If you want to forward the complete message, use the Forward rule.)
Hyperlinks links will be "opened". To avoid this, and if you don't mind converting the messages to HTML, you can use objMsg.HTMLBody = Item.HTMLBody instead (it works with plain text and RTF messages), or create an If Then statement to check for incoming body types and use the correct format. As always, test it with messages to yourself or using objMsg.Display before using it to send messages to others.
Sub SendNew(Item As Outlook.MailItem) Dim objMsg As MailItem Set objMsg = Application.CreateItem(olMailItem) objMsg.Body = Item.Body objMsg.Subject = "FW: " & Item.Subject objMsg.Recipients.Add "email@example.com" objMsg.Send End Sub
More Run a Script Samples:
- Autoaccept a Meeting Request using Rules
- Automatically Add a Category to Accepted Meetings
- Blocking Mail From New Top-Level Domains
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Create Appointment From Email Automatically
- Delegates, Meeting Requests, and Rules
- Forward meeting details to another address
- How to Change the Font used for Outlook's RSS Feeds
- How to Process Mail After Business Hours
- Keep Canceled Meetings on Outlook's Calendar
- Move messages CC'd to an address
- Open All Hyperlinks in an Outlook Email Message
- 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
- Receive a Reminder When a Message Doesn't Arrive?
- Run a Script Rule: Change Subject then Forward Message
- Run a script rule: Reply to a message
- Run Rules Now using a Macro
- Sort messages by Sender domain
- Use a Rule to delete older messages as new ones arrive
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments