Solved

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 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

26 Experts available now in Live!

Get 1:1 Help Now