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 "alias@domain.com" 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 "alias@domain.com" objMsg.Send End Sub
More Information
- 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 a Task from an Email using a Rule
- Create an Outlook Appointment from a Message
- Create Appointment From Email Automatically
- Delegates, Meeting Requests, and Rules
- Delete attachments from messages
- 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
- Macro to Print Outlook email attachments as they arrive
- 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: Autoreply using a template
- Run a script rule: Reply to a message
- Run a Script Rule: Send a New Message when a Message Arrives
- Run Rules Now using a Macro
- Run-a-Script Rules Missing in Outlook
- Save all incoming messages to the hard drive
- Save and Rename Outlook Email Attachments
- Save Attachments to the Hard Drive
- Save Outlook Email as a PDF
- Sort messages by Sender domain
- Talking Reminders
- To create a rule with wildcards
- Use a Macro to Copy Data in an Email to Excel
- 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
Hello.
On outlook 2010, I am trying to run different scrips from VBA modules based on different words in the subject of the email received. It seems that I cannot create more then one script and choose then in rules. Surely there must be way to do such action. Thanks in advance
You can use multiple scripts - one per rule though - unless you use a "stub" macro in the rule and hand off to other macros. You need to use If statements in the macro to do different things based on the words found.
Hi Diane
Thanks so much for assistance and apologies for late reply. Dont have access to internet all the time.
Goal is to forward emails without 'FW' in subject line and forwarding header in the body of the email. I am using your code from above for that and it works great. The problem is as said earlier, based on the words in the subject line and sender, to trigger different rules and scripts with different receiver emails adress. I cannot workout how to solve that.
Once again thanks for assistance and this blog.
You would either use more rules or if statements within a macro. Multiple rules can use the same script - so if action is the same, separate rules might work better.
Hi, I receive some emails with attachments everyday which can be opened only from my computer (sender has given me a digital certificate). I need to forward all these mails to one of my colleague. When I set a rule for autoforward, he receives the mail, but is not able to view the contents or attachments. But when I open the mail in my computer and forward, it works fine. Is there a way to autoforward these mails properly?
Hi,
I'm trying to foward an email automaticly when i receive it. However, I need to Bcc it to a list of contacts that are listed at the beginning of the email an then erase this contact list from the email before sending it..
Is that possible?
Yes, it would be possible. Is the BCC list identified as such? There are different ways to grabbing the list... and the best way depends on how the list is entered.
Hi,
I am trying to send a new message, when a new message arrives, as per the code above.
And it works beautifully, thank you very much.
but i have 2 problems
1) the message i receive, includes images, and the ones i sent using the script, only have placeholders in the original images places.
2) the message body i sent is long, and my outlook signature appears beside (like in a table) the original body.
Can anyone help me with this 2 small issues please?
#1 is difficult to fix - the embedded images are identified by a CID, forwarding breaks it. Forwarding it as attachment would work, but then it's an attachment...
#2: Which script are you using? You may need to add some line breaks or something to add space after the signature.
Hello, I am new to this as well, and I am needing to forward the original email with any attachments, and include a simple instruction statement with it. Such as "process on account xxxx".
The macro at https://www.slipstick.com/outlook/rules/run-script-rule-reply-message/ shows how to do it - change.reply to .forward to use it to forward mail.
Is it possible to auto send an email to an email address within the original email. For instance, someone fills out an online fors, I get an emailed notification telling me their infor from the form. Can I set up an automatic email that sends to the email address within the notification email?
Yes, if you use a macro to grab the address. See https://www.slipstick.com/developer/run-a-script-rule-autoreply-using-a-template/ for a sample.
hi can I also send the outlook emails dynamically to excel/word or CSV. In detail Whenever I receive a mail in a particular folder the email should be also exported to an external document like excel/csv/word real time
You can. This shows how to send to excel - the macro at the end is an items add macro and can be tweaked to work in a run a script rule.
https://www.slipstick.com/developer/code-samples/macro-export-outlook-fields-excel/
I am trying to create a modified "reply with template" script. In short, I will be CC'ed on a email from "Sender" to "Recipient". I would like to reply ONLY to "Recipient" with a template that I have created. Is that possible? If not, then as a backup, I could reply all to both "Recipient" and "Sender", if that is an option.
Thank you.
it is possible - you'd start a new message using the template and copy the recipient address from the original message.
https://www.slipstick.com/outlook/rules/send-a-new-message-when-a-message-arrives/#oof - use item.to as the to address in the new message.