• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Outlook AutoReplies: One Script, Many Responses

Slipstick Systems

› Developer › Outlook AutoReplies: One Script, Many Responses

Last reviewed on August 29, 2018     2 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

I found some really old “cold call” messages in my Inbox from users asking for help that I missed. This is one such message, from Amit, a 7th grader. I feel bad that I missed his message because it's a fun and useful project.

I have a created an extra-curricular activity in Math. I send a problem to my friends in email and when they reply, I have two rules in outlook PROBLEM1_CORRECT followed by PROBLEM1_WRONG.
If the reply email is correct, I use a template and automatic reply goes to sender that they are correct and if they are wrong, I send an automatic reply to them that they are wrong.
I plan to do this everyday.
The problem is the rule only runs one time. So let's say after day2 I have following rules in my outlook defined PROBLEM1_CORRECT, PROBLEM1_WRONG, PROBLEM2_CORRECT, PROBLEM2_WRONG.
Not everyone replies on same day and when people choose to reply to all problems in a single sitting after day 2, the feedback for only one response goes to them not to the other.
I understand that MS Outlook sends email only once to the sender per day. Is there a way I can have the rule run and reply email no matter how many times a responder sends?

The bad news, no you can’t change the automatic reply behavior. It works like this to prevent a mail storm, where two Outlook autoreply to autoreplies that are autoreplies to autoreplies. This happened to me back in the dialup days, and by the time I stopped it the two clients were sending 1 MB messages back and forth.

You have two better options though. You can either use a Run a Script rule to filter the mail, so that only those messages that are responding to your quiz are processed by the script, or you can use an ItemAdd macro to look for email that meets a specific condition, in my example, the subject contains the word "week". (You'll probably want to use a more unique condition though.)

Within the macro, you could use a Select Case statement with the correct answers in the first Case. If the answer doesn’t match, the second Case applies, which sends the Wrong Answer template. The only problem? It’s easy to cheat, as replying with the same answer every time generates a “Correct” template.

Automatically reply

To get past this problem, I'm using an array. The macro looks for a match in the first array and finds the answer in the second array.

For Amit's scenario, my macro assumes the answer is in the subject in this format: Week 1 answer. My macro checks the subject for the week number, finds the matching answer then looks for the answer in the subject.

Can you cheat? Not really, but it will match partial words, so you may want to use leading and following spaces. In my example, 450 is a correct response for Week 1 and owashingtonirving is correct for Week 2. When I use " 45 ", " Washington ", then it gets it right.

To avoid sending autoreplies to follow-up discussions, you'll want to look for additional words in the subject.

The macros below use two templates (as Amit asked), but you can use a standard reply by changing the code a little:

' Do something with the answer 
    Set oRespond = Item.Reply 
    If InStr(LCase(Item.Subject), LCase(strAnswer)) Then 

    ' Add a word or code to the subject so you filter out future replies 
     oRespond.Subject = "Correct " & item.subject 
     Else 
     oRespond.Subject = "Wrong!!!! " & item.subject  

    End If 

    With oRespond 
     .Recipients.Add Item.SenderEmailAddress 
     .HTMLBody = " The correct answer was " & strAnswer & vbCrLf & .HTMLBody 
    ' use .display for testing, .send after it is working as desired 
     '.Display 
     .Send 
    End With 

Run a Script Rule

Create a rule containing the Conditions necessary to identify an answer message. Choose Run a Script as the Action and select this script.

Sub AutoReplyAnswer(Item As Outlook.MailItem) 

    Dim oRespond As Outlook.MailItem 
    Dim strAnswer As String 
    Dim arrQuestion As Variant 
    Dim arrAnswer As Variant 
    Dim i As Long 

    ' Set up the arrays 

    arrQuestion = Array("Week 1 ", "Week 2 ", "Week 3 ", "Week 4 ", "Week 5", "Week 6", "Week 7", "Week 8", "Week 9", "Week 10") 

    arrAnswer = Array("45", "Washington", "Sochi", "1776", "Green", "14", "Richard", "Whale", "18", "Easter") 

      
    ' Go through the array and look for a match, assign it to a string 

    For i = LBound(arrQuestion) To UBound(arrQuestion) 
     If InStr(Item.Subject, arrQuestion(i)) Then strAnswer = arrAnswer(i) 
    Next i 
    Debug.Print strAnswer 

    ' Do something with the answer 
    If InStr(LCase(Item.Subject), LCase(strAnswer)) Then 
     Set oRespond = Application.CreateItemFromTemplate("C:\path\to\correct.oft") 
     Else 
     Set oRespond = Application.CreateItemFromTemplate("C:\path\to\wrong.oft") 
    End If 

    With oRespond 
     .Recipients.Add Item.SenderEmailAddress 
     .Subject = oRespond.Subject & " "& Item.Subject 
     .HTMLBody = " The correct answer was "& strAnswer & vbCrLf& Item.HTMLBody 
    ' use .display for testing, .send after it is working as desired 
     '.Display 
     .Send 
    End With 
Set oRespond = Nothing
End Sub

See Outlook's Rules and Alerts: Run a Script for help using a Run a Script rule and Run a script rule: Autoreply using a template for a simple template script.

ItemAdd Macro

This macro looks for news messages in the Inbox and checks the subject for the word Week. (You'll want to use a more unique keyword.) If Week is found in the subject, it checks to see if Correct or Wrong are also present, so the macro doesn't autoreply if someone replies to the answer message.

You could use a regular rule to move the messages to a folder then watch that folder for new messages, checking to see if they were already replied to.

Option Explicit
Private WithEvents Items As Outlook.Items
 
Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub
 
Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem And InStr(1, Item.Subject, "Week") Then
  GoTo SendReply
  Else
  Exit Sub
  End If

SendReply:
' don't send autoreply if one was already sent
  If InStr(1, Item.Subject, "Correct") Or InStr(1, Item.Subject, "Wrong") Then
  Exit Sub ' to avoid sending an autoreply to a follow-up message
  End If
Dim oRespond As Outlook.MailItem

Dim strAnswer As String
Dim arrQuestion As Variant
Dim arrAnswer As Variant
Dim i As Long
 
' Set up the array
arrQuestion = Array("Week 1 ", "Week 2 ", "Week 3 ", "Week 4 ", "Week 5", "Week 6", "Week 7", "Week 8", "Week 9", "Week 10")
arrAnswer = Array("45", "Washington", "Sochi", "1776", "Green", "14", "Richard", "Whale", "18", "Easter")

 
' Go through the array and look for a match, then do something
For i = LBound(arrQuestion) To UBound(arrQuestion)
    If InStr(Item.Subject, arrQuestion(i)) Then strAnswer = arrAnswer(i)
Next i

Debug.Print strAnswer

If InStr(LCase(Item.Subject), LCase(strAnswer)) Then
    Set oRespond = Application.CreateItemFromTemplate("C:\path\to\correct.oft")
       Else
    Set oRespond = Application.CreateItemFromTemplate("C:\path\to\wrong.oft")
End If

With oRespond
    .Recipients.Add Item.SenderEmailAddress
    .Subject = oRespond.Subject & " " & Item.Subject
    .HTMLBody = " The correct answer was " & strAnswer & vbCrLf & Item.HTMLBody
' use .display for testing, .send after it is working as desired
    '.Display
    .Send
End With

Set oRespond = Nothing
End Sub

More Information

  • Outlook's Rules and Alerts: Run a Script
  • 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
  • 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: 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
  • 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
Outlook AutoReplies: One Script, Many Responses was last modified: August 29th, 2018 by Diane Poremsky

Related Posts:

  • Run a script rule: Autoreply using a template
  • How to Process Mail After Business Hours
  • Run a Script: Send Autoreply with Date
  • A simple run a rule script marks Outlook messages read when the messag
    Use a run a script rule to mark messages read

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
2 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Pratap Rajput (@guest_215415)
June 12, 2020 10:20 am
#215415

you are amaizing.....

0
0
Reply
Najam (@guest_200470)
August 5, 2016 4:17 pm
#200470

Hi Diane,
This is my first experience with outlook macros. I could not find anything that would create a new e-mail only when a certain string in a received e-mail is present and send the new e-mail with a message and the string found.

I think my request is generic but there are no samples. May you please guide.

1
-1
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 19

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment