Solved

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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