Run a Script Rule: Send a new message when a message arrives

Last reviewed on March 14, 2014   —  121 comments

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 ""


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


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 ""


End Sub

Written by

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.

Please post long or more complicated questions at Outlookforums.

121 responses to “Run a Script Rule: Send a new message when a message arrives”

  1. Manuel Ratzinger


    thx for that usefull post. I have a little different problem to solve. Do you know how it is possible to do the same thing as above but use a "alias" mail address to send the reply mail as a user could choose manualy in the "From..." Menue in a new Outlook E-Mail User Interface.

    I know the possibility with the SendUsingAccount method, but the problem is there is no additional account but the user has only the right to send as another user.

  2. Eric

    I'm trying to use the To Forward the message body to another address script and I get a compile error on the first line. User-defined type not defined. I have excel 2010. Please help. Thanks

  3. Manuel Ratzinger

    Thx, I figured that out already. Works fine for me.

  4. Eric

    Yes, but I've added a forwarding message and an email address. Sorry, first time trying to use the script option.

    objMsg.Subject = "FW: Forwarded to supportcase " & Item.Subject
    objMsg.Recipients.Add ""

  5. Eric

    Got it to work. :)

  6. Barney

    Hi There
    I have an Outlook 2010 rule that runs whenever any emails from a specific user, with specific subject line and body text is detected. I know this rule works as I set up this rule with a simple forward rule and it work.
    However I want to execute your script 'New message using a template' as I want to trigger a whole new email and send it to specific users.
    I copied your code, followed your instructions but nothing happens.
    the outlook template file resides in c:\OFT\Rule1.oft
    This is what my script looks like
    Sub SendNew(Item As Outlook.MailItem)

    Dim objMsg As MailItem
    Set objMsg = Application.CreateItemFromTemplate("C:\OFT\Rule1.oft")

    ' If the address you want to send to is not saved in the template,
    ' set the addresses here
    bjMsg.Recipients.Add ""


    End Sub
    How can I toubleshoot this further? Any help would be greatly appreciated.

  7. Barney

    Hi Diane
    I have checked and the syntax was correct, also changed the 'send' to 'display' when I run the rule the template does not open.
    Sub SendNew(Item As Outlook.MailItem)

    Dim objMsg As MailItem
    Set objMsg = Application.CreateItemFromTemplate("C:\OFT\Rule1.oft")

    ' If the address you want to send to is not saved in the template,
    ' set the addresses here
    objMsg.Recipients.Add ""


    End Sub

  8. Mark

    Diane - looking for a variation on this - wondering if you can help me. At our work site, I can't sync my google calendar with my work calendar because it's blocked. So I have a rule to forward meeting requests to my google calendar. The problem is that we also use "all day events" as a way to show someone is out of the office. I don't want these appointments forwarded to my google calendar, and I can't find a way to exclude them from the rule.

    Any advice?


  9. Mark

    No, I currently just have a standard rule created through the Outlook rules wizard. Just trying to find a way to forward only meetings that are not all day events. The rules wizard doesn't account for this, and it looks as though I need to use a script or macro.

  10. Misa

    Hello,Can anyone help me with this issue : How to make "personalized auto-responder", if I can call it this way....
    Any decent WEB site today have (if we can call it) customized auto reply message when customer sign up with them.
    Example : If I register with some WEB site I receive message similar to this:
    Dear Misa,Thank you for registering with our website.
    Your details are as follows:-
    Username: Misa
    Password: Provided when you registered.
    So in just few seconds I'm receiving automated message with my name and user name,also if I loose password I can recover it.
    Can anyone tell me how I can get something like this, do I need additional software (or service)?Many thanks

  11. Barney

    The outlook template file does not display, nor do I get the message box pop up. Wondering if these things may be blocked by group policy, do you know?

  12. Barney

    the macro setting in my outlook is set to 'Notifications for digitally signed macros, all other macros disabled' and this is greyed out, therefore I cannot change the setting. Must be set by GP. Are you familiar with how I can disable this via local security policy?

  13. Misa

    Yes Diane, I would need this for my WEB site. When I contacted support they told me that I need script for this, and now I'm looking for someone who can help me with it...

  14. Rupesh

    what i have to insert in this option objMsg.Body

  15. seb

    hi there, i like this but was looking for a script that allowed me to automatically forward an email to with a message in the body. ie please see my email below.

  16. Alap

    Hi there,

    We are in a situation where we have a mailbox, which receives e-mails from The body of the e-mail contains our customer's e-mail address specified as E-mail Address:

    We would like these e-mails to be forwarded to the customers by picking up the E-mail Address field in the body.

    Is there a script for this?

  17. Richard

    Hi Diane
    I have used your script successfully thanks. However I would like to add multiple email recipients, and i have tried simply delimiting and repeating the objMsg.Recipients.Add line but to no avail.

    Any ideas?



  18. Richard

    Hi Diane, and thanks for the reply.

    I have tried the semi colon between email AD's but that seemed to only send to the first email in the list. Having said that, now it has stopped working all together, but there are no error messages popping up. Please see a copy of script below. Sorry I am not great at scripts, although am technical.

    Sub SendNew(Item As Outlook.MailItem)
    Item.Subject = ",,[Our ref: 2M7W2NSI5NruqKI]"

    Dim objMsg As MailItem
    Set objMsg = Application.CreateItemFromTemplate("C:\old\webserver.oft")
    objMsg.Recipients.Add ";;;"


    End Sub

    The module code is below also

    Sub webserver()

    End Sub

  19. Craig Johnstone

    if you just want to forward the subject only then use the following script

    Sub SendNew(Item As Outlook.MailItem)
    Dim objMsg As MailItemSet
    objMsg = Application.CreateItem(olMailItem)
    objMsg.Body = ""
    objMsg.Subject = "FW: " & Item.Subjectobj
    Msg.Recipients.Add ""
    End Sub

  20. Heri

    Diane - looking for a variation on this - wondering if you can help me. I have tried "To Forward the message body to another address" script and its working perfectly but having issue with attachment, script not able to forward attached file/files in the email, can you please advice how to forward attachment with email body ??

    Many thanks

  21. Karen

    Hi Diane, thank you for all of your posts and help so far :)
    I am using the "Send BCC" VBA code (life saver) however every now & then Outlook 2010 (on Win 8, 64) stops processing the macro after a reboot, and I don't always remember to check that the BCC is still active.

    Is there a way (I have googled but it assumes I'm referring to the auto send/receive at startup), to create an email at startup so it triggers the BCC and I can confirm it is working. .

    Eg: Outlook 2010 starts / Auto send mail to (
    the Auto BCC triggers and I get an alert on my device "email received at"

    Many thanks in advance,


  22. Karen

    I put the following code in as a Application_Startup item
    So far it seems to have worked. :) Thank you for the advice on the reminders. Reminders always trigger on startup, so that's a handy redundancy feature. :)

    Private Sub Application_Startup()
    'Creates a new e-mail item and modifies its properties'

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item'
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
    .Subject = Format(Now, "YYYYMMDD - HH:mm:ss") & " | " & "Login Test"
    .Body = Format(Now, "YYYYMMDD - HH:mm:ss") & " | " & "Testing the BCC"
    .To = "me@forme"
    End With
    End Sub

  23. Pete

    Hi, I'm looking for a bit of help with a script. When I'm bcc'd on an email I want to send a new email to the original email recipient. The email needs to include an attachment and ideally the attachments vary by email domain name. I can't find the commands that I need, please could someone point me in the right direction. Thanks

  24. Tex


    I tried the code it works for me.But then, my problem is with Rules that i have set to run the script. Say, my Rule looks for the keyword 'xyz' in the subject line of received mail and triggers the script to forward the mail to a bigger group that includes myself. I again get the mail with 'xyz' in the subject line. This kind of, puts it in a loop!! Please suggest how to avoid this.

  25. Tera

    Thank you for sharing this script!
    I have gone through the steps and was able to complete a successful test. However, as soon as I change the filter on the rule itself the script no longer sends or displays.

    I've deleted the rule and set up a new rule, but the problem continues.

    Please advise.

  26. Tera

    (I mean a condition in the rule, not filter....)

  27. Tera

    searching the subject or body for words/phrases. I changed it from a phrase to a word.

  28. Tera

    Yes Ma'am. The word is in the body and the subject. I've changed it from awaiting approval to approval.
    What make this even more interesting is, if I delete the rule and set it up again it will not display either.

  29. Tera

    Unsigned macros were disabled! You are wonderful. Thank you for all your help and sharing your knowledge.

  30. Jenny C

    HI Diane, how do I add a short message before it gets forwarded?

    I have used this and it works
    Sub ChangeSubjectForward(Item As Outlook.MailItem)
    Item.Subject = "Test"

    Set myForward = Item.Forward
    myForward.Recipients.Add ""


    End Sub

    But I'd like to add a message which would be a reference for the email being sent

    Thank you

  31. Nasim Rawat

    HI Diane,
    I want to trim some rows of message body and then forward, can you help me.

  32. nasim rawat

    i want to delete top 50/60 rows or 300 words, but below this all message send

  33. Russell Brown

    So here is a tricky one for you. I want to auto reply with a script but I want it to automatically reply when a vote is sent out. The vote contains times when you would like to attend the meeting. I would like when the vote email is sent to me, to be able to auto reply that I would like to attend at 11:00. Is this possible?

  34. Russell Brown

    Yes, it is always a voting message.

  35. Doug

    I think your script gets me almost to where I need to be. I'm trying to autoforward a message only when it's received from a particular email address. Can you suggest a modification that would make this work? Thanks!

  36. Russell Brown

    OK, Let me know what other specific information you might need to write the script. I would REALLY appreciate it!

  37. Nasim rawat

    HI Diane,
    I want to auto forward email without adding previous sender or receiver,
    this is news email that send by sender on multiple user ids when i forward it it add all email ids in message body, some emails have attachments. I am beginner in VBA.

  38. Anonymous

    I was using a variation of your last example successfully several weeks ago, but for some reason when I tried to enable it again today I am not getting any notifications sent out. I just want an email sent to my personal email address with the name/email of the sender in the subject/body when new email arrives (I do not want the body/subject of the original email address sent to my personal email address due to security concerns). Here is the script. The top is my attempt at modifying yours. The bottom with all the ' marks was the one that worked great previously. Where I say is my personal email which I don't want to include on here. Thank you for your help!

    Sub SendNew(Item As Outlook.MailItem)

    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)

    objMsg.Body = Item.Sender
    objMsg.Subject = Item.SenderEmailAddress
    objMsg.Recipients.Add ""


    End Sub
    'Sub SendRuleMail(objItem As Outlook.MailItem)
    ' Dim objMail
    ' Dim strMsg
    ' 'Create a message object
    ' Set objOutlk = CreateObject("Outlook.Application")
    ' Set objMail = objOutlk.CreateItem(0)
    ' 'Create a new message
    ' objMail.To = ""
    ' objMail.CC = "" 'Enter an address here To include a carbon copy; bcc is For blind carbon copy's
    ' 'Set up Subject Line
    ' objMail.Subject = objItem.Sender
    ' 'Add the body
    ' strMsg = objItem.Sender 'I used the subject of the new mail for the body
    ' objMail.Body = strMsg
    ' objMail.Send
    ' 'Clean up
    ' Set objMail = Nothing
    ' Set strMsg = Nothing
    ' Set objOutlk = Nothing
    'End Sub

  39. Anonymous

    I figured out the problem in my previous question yesterday - the macro settings were too restrictive so it was blocking my script. Now I am wondering if there is a way to adjust the script to automatically delete the message from my sent mail?

  40. Nasim rawat

    yes i have also include attachment.

  41. Anonymous

    Thanks. I figured it out. I am copying my code below in case it helps anyone else.

    Sub SendNew(Item As Outlook.MailItem)

    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)

    objMsg.Body = Item.SenderEmailAddress
    objMsg.Subject = Item.Sender
    objMsg.Recipients.Add ""

    objMsg.DeleteAfterSubmit = True


    End Sub

  42. Nic Xiaoyu Qi


    I am trying to make a macro to forward a email but include the selected email as an attachment.
    I've got everything to work apart from attaching the selected email as an attachment.

  43. Kathy Oliver

    If I use the script for the auto reply, will the auto reply work every time a new email is received by the same sender? We are looking for the auto reply to send every time an email is sent by the same sender while the rule is in place.

  44. Michael Martin

    Diane, I would like to create a rule / script that can read two emails by the subject line and forward a mail to another email address.

    example: i recieve an email with subject line "Problem" at 9:00 am. I get another email in 30 minutes later with the subject line "Resolved".

    If i do not get in 30 mins the resolved email, i want to forward this problem email to another email address. how can i set this up by creating rules / scripts? please help

  45. Michael Martin

    Diane, Thanks for your response. Appreicate if some one can develop this addin for me. what will it cost?

  46. Anthony Parchmont

    Hi Diane, In the “To Forward the message body to another address” How can I forward the original email as an attachment and add a custom static message body to say “ please see the attached message”

    I would be grateful for your help on this one.

  47. Anthony Parchmont

    Thank you, works like charm!

    1. Anthony Parchmont

      Hi Diane, What can I do if I just want to forward only the attachments, but just specific file extension such .xls, .doc., .pdf. Other files like .png, .gif, .jpg should not get forwarded. The code below is what I used to forward only attachments, but it attaches all attachments.

      Sub RunAScriptRuleRoutine(MyMail As MailItem)
      Dim strID As String
      Dim olNS As Outlook.NameSpace
      Dim msg As Outlook.MailItem
      Dim fwd as Outlook.MailItem

      strID = MyMail.EntryID
      Set olNS = Application.GetNamespace("MAPI")
      Set msg = olNS.GetItemFromID(strID)
      ' do stuff with msg, e.g.
      Set fwd = msg.Forward
      fwd.Body = ""
      fwd.To = ";"

      Set msg = Nothing
      Set fwd = Nothing
      Set olNS = Nothing
      End Sub

      Please help me with one.

  48. Ken Rogers

    I have a custom form that users enter a URL in one field and then, with some VB scripting, the recipient can click on a separate button to launch the URL. This works great until the original recipient forwards the form. When forwarded, the VB scripting gets disabled so no links. Funny thing - I opened the forwarded form in my developer tab and ran from there and the links worked.

  49. Josh Heo

    Sorry.. I am not sure if my previous question was uploaded.

    I cannot see pictures when I use this script to auto forward emails.
    I see "x" and "the linked image cannot be displayed"

    How can I correct it?

  50. Josh Heo

    Hi, Thanks again for the help..
    Hmm.. I am still unable to see the picture after auto forwarding it to myself to test it...
    I tried to "click here to download pictures..." and still same "x"
    Anything else to try out?

    Thank you.

  51. Ashleigh

    Hi, I have used script to change the name of an email and auto forward it regularly. Is was wondering if there is a way i can ensure the person who receives it can not auto forward it?

  52. Ry

    How feasible is it to write a program to create rules in Outlook? I have a batch of rules I'd like to give to multiple users and would love to not have to create them for each person. The variables in the rules are almost the same for every user and could be tweaked to make it the same for every user as well.

  53. Dheeraj Poojari

    Diane, brilliant post on outlook automation. Quick query to the one above(linked images by Josh). Instead of forwarding, I am using "reply" to respond using a particular oft template. The images do not come up, and they show the linked images error. Can you help me with modifying the code? Below is the code.

    Sub ForwardGeneralNew()
    Dim oExplorer As Outlook.Explorer
    Dim oMail As MailItem
    Dim Item As MailItem
    Dim rMail As MailItem
    Set oExplorer = Application.ActiveExplorer
    Set oMail = oExplorer.Selection.Item(1).Forward
    oExplorer.Selection.Item(1).UnRead = False
    Set rMail = Application.CreateItemFromTemplate("C:\Macros\General.oft")
    On Error GoTo Release
    If oExplorer.Selection.Item(1).Class = olMail Then
    oMail.Subject = "Testing a auto reply"
    oMail.HTMLBody = rMail.HTMLBody _
    & vbCrLf & oMail.HTMLBody
    CopyAttachments oMail, Item
    oMail.Recipients.Add ""
    If oMail.Recipients.Item(1).Resolved Then
    ' oMail.Save
    oMail.UnRead = False
    MsgBox "Could not resolve " & oMail.Recipients.Item(1).Name
    End If
    MsgBox ("Not a mail item")
    End If
    Set oMail = Nothing
    Set oExplorer = Nothing
    End Sub

  54. Lance Hames


    I am trying to send an email draft when a particular email arrives. Where should I look to start for this? Is it something that can be done with this script?


Leave a Reply

If the Post Coment button disappears, press your Tab key.