|
 |
access thread: Read Outlook Express Mail from Access 2000
Message #1 by GrahamArchbold@c... on Mon, 18 Jun 2001 10:51:46 EDT
|
|
I wish to read e-mail messages from Outlook Express which have been generated
by my web site via a mail form.
The mail form produces structured (sort of) e-mails (enquiries / orders - I
hope - etc). What I need to do is read them into my Access application for
processing.
Basically I want to run an Access process which will offer up the unread mail
in the in-box, allow me to select a mail item then read the data in to my
Access application so I can validate it and store it away.
At the moment I am struggling to Access to pull up Outlook mail messages -
any ideas?
Message #2 by "Mike" <mike.day@o...> on Mon, 18 Jun 2001 17:14:21
|
|
> I wish to read e-mail messages from Outlook Express which have been
generated
> by my web site via a mail form.
>
> The mail form produces structured (sort of) e-mails (enquiries / orders -
I
> hope - etc). What I need to do is read them into my Access application
for
> processing.
>
> Basically I want to run an Access process which will offer up the unread
mail
> in the in-box, allow me to select a mail item then read the data in to my
> Access application so I can validate it and store it away.
>
> At the moment I am struggling to Access to pull up Outlook mail messages
-
> any ideas?
>
try this:
this will scan your inbox and look for a subject , it will then append a table.
first create a table 'tblTempTable' and copy the following code into a new module.
This code will search for mail with the subject 'TEST' and populate the table.
Change this to search for what you need.
Private Sub FindMail()
Dim rs As Recordset
Dim OutLookApp As Outlook.Application
Dim OLInbox As Outlook.MAPIFolder
Dim OLInboxItems As Outlook.Items
Dim OLMailobject As Object
Dim SubjectLine As String
Set OutLookApp = CreateObject("Outlook.Application")
Set OLInbox = OutLookApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set rs = CurrentDb.OpenRecordset("tblTempTable")
SubjectLine = "Test"
If SubjectLine <> "" Then
Set OLInboxItems = OLInbox.Items.Restrict("[Subject] = """ & SubjectLine & """")
Else
Set OLInboxItems = OLInbox.Items
End If
For Each OLMailobject In OLInboxItems
rs.AddNew
rs!Subject = OLMailobject.Subject
rs!sentby = OLMailobject.SenderName
rs!To = OLMailobject.To
rs!Message = OLMailobject.Body
rs!Date = OLMailobject.SentOn
rs.Update
Next
Set OutLookApp = Nothing
Set OLInbox = Nothing
Set OLInboxItems = Nothing
Set OLMailobject = Nothing
Set rs = Nothing
End Sub
Message #3 by GrahamArchbold@c... on Wed, 20 Jun 2001 05:34:56 EDT
|
|
I got Mike Day's code to work apart from two bizarre things (see orginal code
I am using below)
1. When I run access the Outlook it keeps returning the same 4 'records' -
one e-mail twice and 2 others - even though I have deleted one of the old
mails and added a new one matching the test criteria, restarted the
applications, rebooted the machine, compacted outlook and scratched my head a
lot.
2. The attempt to build the record set produces a type mismatch (run time
error 13) (for testing I have been outputting to a file) on the line
Set rs = CurrentDb.OpenRecordset("tblTempTable")
in the code below, I thought I had all the libraries open but for the life of
me I cannot identify the cause of the mismatch
(note, in the running version I have replaved the references to rs with a
text file which I print the details to, and the body type is HTML)
Private Sub FindMail()
Dim rs As Recordset
Dim OutLookApp As Outlook.Application
Dim OLInbox As Outlook.MAPIFolder
Dim OLInboxItems As Outlook.Items
Dim OLMailobject As Object
Dim SubjectLine As String
Set OutLookApp = CreateObject("Outlook.Application")
Set OLInbox =
OutLookApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set rs = CurrentDb.OpenRecordset("tblTempTable")
SubjectLine = "Test"
If SubjectLine <> "" Then
Set OLInboxItems = OLInbox.Items.Restrict("[Subject] = """ &
SubjectLine & """")
Else
Set OLInboxItems = OLInbox.Items
End If
For Each OLMailobject In OLInboxItems
rs.AddNew
rs!Subject = OLMailobject.Subject
rs!sentby = OLMailobject.SenderName
rs!To = OLMailobject.To
rs!Message = OLMailobject.Body
rs!Date = OLMailobject.SentOn
rs.Update
Next
Set OutLookApp = Nothing
Set OLInbox = Nothing
Set OLInboxItems = Nothing
Set OLMailobject = Nothing
Set rs = Nothing
End Sub
|
|
 |