Solved

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

Posted on 2013-06-25
5
327 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
  • 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
If you don't know how to downgrade, my instructions below should be helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now