Solved

Reading Outlook2010 New EMail Bodies and sending pieces to Access 2010 table

Posted on 2013-06-25
5
336 Views
Last Modified: 2013-06-26
I'm pretty good at Access vba, but havent explored much with Outlook
I get a certain amount of emails coming in mentioning jobs.  Each mail message contains a formated body that I would like to parse, place into a database if it is a new one and then notify me of only the new jobs.

I would like to do this from Outlook 2010 so it would work like this:
1) Extract body
2)  Is it from a Job_Sender in the Access Table
3)  If so, parse Body
4)  Take Job title, company, location, date of message, and link.
5)  Store in Access table if these are new.
6)  Compose new email to me daily at a certain time (4pm)  that just lists the new items

Where do I place the code ?
How can I get to the new bodies only?
Can I get to hyperlinks within the body?

Any help would be appreciated.
0
Comment
Question by:GNOVAK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39276722
Hi, GNOVAK.

Do you want the solution to run automatically (like an Outlook rule) or do you want to run it manually.
0
 

Author Comment

by:GNOVAK
ID: 39276731
I would prefer automatically. The parse part as new mail comes in, the creation of the new mail at a specified time....
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39276764
Where do I place the code ?
The code will go in Outlook.  You'll place it in a code module (e.g. Module 1).

How can I get to the new bodies only?
Create a rule that's triggered by the messages you want to process.  Set the rule's action to "run a script" and select your script as the one to run.  The script itself will look something like this.  I can't be more specific without knowing more about the format of the messages and the data you want to pull from them.

Sub GNOVAK(Item As Outlook.MailItem)
    Dim strBody As String
    'Extract the message body
    strBody = Item.Body
    'Check the Access table.  The function InAccessTable, which you will need to provide, will return True if the item is in the table
    If InAccessTable() Then
        'Code to parse the body goes here
        'Code to add the parsed data to Access goes here
    End If
End Sub

Open in new window


Can I get to hyperlinks within the body?
Yes.  How you do that depends on what format the messages are in.

Composing the new message is easy enough too.  Triggering creation requires more code.  Outlook doesn't have a built in means of doing that, so we have to be creative.  The approach I generally use is to trap the ReminderFire event.  This event fires each time a reminder fires.  Using some code we can check to see if the item that triggered the reminder is a task.  If it is, then we can check the subject to see if it's the right task  If it is, then the code creates and sends the message.  Something like this.  Of course you'll need to fill in the particulars.

Dim WithEvents olkReminders As Outlook.Reminders
 
Private Sub Application_Quit()
    Set olkReminders = Nothing
End Sub

Private Sub Application_Startup()
    Set olkReminders = Application.Reminders
End Sub

Private Sub olkReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Dim olkTask As Outlook.TaskItem, olkMsg As Outlook.MailItem
    If ReminderObject.Item.Class = olTask Then
        Set olkTask = ReminderObject.Item
        If olkTask.Subject = "Send Daily Message" Then
            Set olkMsg = Application.CreateItem(olMailItem)
            With olkMsg
                .Subject = "Your Subject Goes Here"
                .To = "someone@company.com"
                .Body = "Your message goes here"
                .Send
            End With
            ReminderObject.Dismiss
        End If
    End If
    Set olkTask = Nothing
    Set olkMsg = Nothing
End Sub

Open in new window

0
 

Author Comment

by:GNOVAK
ID: 39280022
Thanks so much!
That was EXCELLENT!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39280042
You're welcome!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question