-2

I am trying to speed up a process and wanted to know if what I'm thinking is possible. We have emails that are auto-generated, that when they arrive, we search the body for specific phrase. If that phrase is found, we reply with the entire line of text that the phrase appears in. Would it be possible to make a rule that would achieve the same thing?

For example:

An email arrives, triggering the rule. The rule searches the body of the email for "not associated", if it finds that phrase, it does a "Reply All" and pastes "We're sorry, but the file is not associated with this plan",the entire sentence containing the search text, at the top of the reply body. For a little more reference, the line of text is always on it's own line and followed by a blank line.

I'm using Outlook 2013. As far as what I've tried, I'm basically stuck because I can't figure out how to get outlook to copy a specific line of text. I have no real programming experience, but am pretty good at looking at code and modifying variables to work with my data. I have tried to find some code to get me in the right direction, but can't seem to find anything that seems like it would work.

Mr.Syrax
  • 396
  • 1
  • 9
  • 26
  • 1
    [Which programming language?](http://stackoverflow.com/help/tagging) [What have you tried so far?](http://whathaveyoutried.com) [Please show us your code.](http://stackoverflow.com/help/mcve) – GoBusto Feb 19 '15 at 14:37
  • Updated the post. No code to show, n00b at the helm! :0) – Mr.Syrax Feb 19 '15 at 14:41

1 Answers1

1

Syrax,

You can set up a rule in Outlook to detect a specific word in the body and call a VBA macro if it found. In that case a MailItem instance will be passed to youe code where you can do whatever you need. For example:

Public Sub Test(mail as MailItem)
    ' do whatever you need
End Sub

In the code you need to use the Reply method of the MailItem class to create a reply, pre-addressed to the original sender, from the original message. Then you can change the message body - see Body, HTMLBody properties. You can read about all possible ways of working with item bodies in the Chapter 17: Working with Item Bodies. When you are done, you need to call the Send method of the MailItem class which sends the e-mail message. That's all.

Be aware, the current site is for developers. So, it is expected that you know the basics of Outlook programming. That's why I'd recommend starting from the Getting Started with VBA in Outlook 2010 article in MSDN.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45