Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Outlook search and reply....

Status
Not open for further replies.

RollingMoose

Programmer
May 13, 2002
73
US
I'm not sure where to ask this, but I'm hoping someone can point us in the right direction. We would like to scan the body of email messages received in Outlook and send automatic replies to the sender based on the frequency of certain words appearing in the body of their email. Any suggestions on where to start or a site or link to information would be appreciated.
 
Hello,

You might want to check out Sue Mosher does a real nice job with questions on that site.

In the Outlook VB editor, right click on ThisOutlookSession and select ViewCode. One of the Application events you can trap is NewMail (unfortunately it doesn't expose the item just received).

The Outlook object you are interested in is the MailItem. It is olMailItem in the enumerations. There are some properities you can interrogate to ensure you have a mail item and not a contact item, etc.

Once you have a valid MailItem, then you want to scan the Body property with the code you referenced above.

Outlook's object model is very different from any of the other Office products because it is not Document centric.
An individual email is opened up in an inspector which is part of the NameSpace if my memory serves me correctly.

Set objApp = CreateObject("Outlook.Application")
Set objNameSpace = objApp.CreateNamespace("MAPI")
Set objInspector = objNameSpace.GetInspector(?)

Sorry, the above is off the top of my head, so please accept my apologies if there are mistakes in it. It will hopefully at least get you started.

Another gotcha to be aware of is the Security patch will prompt you for permission to send an email when you reference an address with your autoreply feature. There is no way to program around it but there is an excellent 3rd party product which creates wrappers around Extended MAPI to allow you to work with it. Check out It is worth the money.

Good LucK!


Have a great day!

j2consulting@yahoo.com
 
I once wrote a macro that does something quite similar to what you are asking. Let me ask you this, do these emails you recieve follow any type of set template/format or are they all unique and appear very different each time you recieve them. Do the emails have the same or similar subject line and do they appear in their own subfolder or do they sit in your main inbox with other non-related emails? You need to have a way or telling your macro which emails you want the code to execute on. Generally this is done based on the subject line, the location of the emails, or even based on who sent it. Can you post a sample of the body of the email so I can see how it appears when you receive it. Also, exactly what strings in the body do you want to search for?

One more thing, how do you want the macro to run? Will the macro start automatically or do you plan on running it manually. If you want it to run automatically you will need some code in the NEW_MAIL event of your Outlook session. One problem with using the New Mail eventis that it fires only once if your receive multiple emails at one time. This means you would need to loop through multiple emails to find the ones that you want the code to run on. Since there will probably be old emails in the same location you would need to code your application to only execute on email that is unread and then set them to read after you've extracted you data from them.


Rollin Again
 
QUOTE: "Another gotcha to be aware of is the Security patch will prompt you for permission to send an email when you reference an address with your autoreply feature. There is no way to program around it"


Are you not able to use send-keys to get around these prompts. I have gotten various security prompts in Outlook before and I have always been able to code send-keys to get around them.



Rollin Again
 
Sorry, yes you can use SendKeys as a work-a-round. I have some code somewhere that uses WSH to do this. I was speaking in terms of an automated system. It looks ugly to have the form show up and disappear.

Also, if there are distinguishable characteristics about the incoming message, you could use rules to send it to a specific folder and run your code against that folder.

Good LucK!

Have a great day!

j2consulting@yahoo.com
 
QUOTE: "You could use rules to send it to a specific folder and run your code against that folder."

This is what I have done in the past with my Outlook macros. The only thing to remember still is that you must include logic in your code to flag each email in the folder as being read after the macro has been run on it. This way you don't run the macro on messages that have already processed by the macro before at an earlier date.

The only other way I can think of it other than checking the "Read" status of each message is to actually move the emails that have been processed by the code to a completely different folder. This way you always have one folder with unprocessed emails and another with the processed ones. The code would then always look to the unprocessed email folder for files to use.

Rollin





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top