apatton.cnet
apatton.cnet

Reputation: 13

Programmatically reply to an email in Outlook

I'm writing a script that replies to every email coming in.

I have made a rule to run on all incoming messages that runs a script, sets the category, and marks as read. The rule sets the category and marks as read, but doesn't run the script. Below is my code:

Sub reply(Item As Outlook.MailItem)

    MsgBox "Hey this script is running!"

    On Error GoTo ErrorTrap

    Dim MsgReply As Outlook.MailItem
    Set MsgReply = Item.reply
    With MsgReply
        .Subject = "Welcome to IT Business Builder"
        .HTMLBody = "This is just a test"
        .Body = "This is just a test"
        .Send
    End With
    Set MsgReply = Nothing
ErrorTrap:
    MsgBox Err.Number & " " & Err.Description & " message not sent because of error"

End Sub

After running the rule, no message box pops up, no emails are sent.

Upvotes: 0

Views: 10255

Answers (1)

Sandesh Jadhav M
Sandesh Jadhav M

Reputation: 65

If your email does not change each time. You can use Outlooks inbuilt feather of auto reply. It sends the given email to all of them who send an email to your email ID.

Click Here to See how to set it up

To quickly summarise...

  1. Create a new message with subject and body you want to send as auto replying.
  2. Click File (in Outlook 2007, click the Office button) > Save As.
  3. In the Save As dialog box, select Outlook Template in the Save as type drop-down list, and then click the Save button.
  4. Close the message directly. If you are using Outlook 2010, 2013 and 2016, please click Home > Rules > Manage Rules & Alerts.

For Outlook 2007, click Tools > Rules and Alerts... from the menu in Outlook window. See screenshot:

  1. In the Rules and Alerts dialog box, click New Rule...
  2. In the Rules Wizard dialog box, select Apply rule on message I receive in Outlook 2010 and 2013. And In Outlook 2007, select the Start from a blank rule option and the Check messages when they arrive option, and click Next button.
  3. In the following Rules Wizard dialog box, select sent only to me in Outlook 2010 and 2013, or select where my name is in the To box in Outlook 2007, and then click Next button.
  4. Check reply using a specific template under Select action(s), and click on a specific template in the Edit the rule description box. See screenshot:
  5. In the Select a Reply Template dialog box, select User Templates in File System in the Look In drop-down list, select the template you created before and click the Open button. When it returns to the previous Rules Wizard dialog box, click the Next button.
  6. In the next Rules and Wizard dialog box, click the Next button without checking any exceptions.
  7. Type a name for your auto reply rule in the Specify a name for this rule box, and click the Finish button.

If you want to use this rule for all email accounts, please check the Create this rule on all accounts box.

  1. Now it returns to the Rules and Alerts dialog box, please click the OK button. Now the auto reply rule is created.

Upvotes: 1

Related Questions