Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Outlook 1

Status
Not open for further replies.

Ma3x323

Programmer
Jun 27, 2001
148
US
OK, I am assigned a project to read emails from Microsoft access. This program is supposed to read emails, read the TO, BCC, CC and the body and grab the email addresses in it.
The big problem is that I do not know how Outlook Interface works. Can anybody give me pointers or hints of how to do this. I know I need to do lots of parsing.
I'd like to do this in C++, but if somebody would think that doing this in VBA would be better, please notify me and explain why.

Thanks in advance. -Feryl
--> Just a silly software engineer wannabee.
If you feel a post has been helpful to you, click on the link at the bottom of their post to cast a vote for "TipMaster Of The Week". You don't need to be the one who asked the question to vote.
 
I am not sure of the best way to do this, I did it in VBA because I could. It does some stuff that I am sure does not apply to your situation, but I as sure that you can take out what you do not neeed.
<CODE>
Public Function ImportInbox()
On Error GoTo Err
Dim TempRst As Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.mapiFolder
Dim InboxItems As Outlook.items
Dim Mailobject As Object
Set OlApp = CreateObject(&quot;Outlook.Application&quot;)
Set Inbox = OlApp.GetNamespace(&quot;Mapi&quot;).GetDefaultFolder(olFolderInbox)
Set TempRst = CurrentDb.OpenRecordset(&quot;tblInbox&quot;)
Set InboxItems = Inbox.items
For Each Mailobject In InboxItems
With TempRst
.AddNew
TempRst!inboxSubject = IIf(Mailobject.Subject = &quot;&quot;, &quot; &quot;, Mailobject.Subject)
TempRst!inboxFrom = Mailobject.SenderName

Dim loc, locLen, locPos As Integer
Dim locString As String
Dim locStr As String
locStr = &quot;a&quot;
locPos = 0
locLen = Len(Mailobject.SenderName)
Do While IsNumeric(locStr) = False And locPos <> locLen
locPos = locPos + 1
locStr = Mid(Mailobject.SenderName, locPos, 1)
Loop
Dim dbGetRegion As Database
Dim qryGetRegion As QueryDef
Dim rstGetRegion As Recordset
Set dbGetRegion = CurrentDb
If locPos < locLen Then
locString = Mid(Mailobject.SenderName, locPos, 3)
loc = locString
'gets the loc
Set qryGetRegion = dbGetRegion.CreateQueryDef(&quot;&quot;, &quot;SELECT FacilityCode, REGION FROM Facility WHERE FacilityCode=&quot; & loc)
Set rstGetRegion = qryGetRegion.OpenRecordset()
!loc = loc
ElseIf InStr(1, Mailobject.SenderName, &quot;,&quot;) > 0 Then
Dim lName As String
lName = &quot;*&quot; & Left(Mailobject.SenderName, (InStr(1, Mailobject.SenderName, &quot;,&quot;)) - 1) & &quot;*&quot;
'gets the region or district
Set qryGetRegion = dbGetRegion.CreateQueryDef(&quot;&quot;, &quot;SELECT NAME, POSITION, [REGION #], DISTRICT FROM tblEMailLPMs WHERE NAME Like '&quot; & lName & &quot;'&quot;)
Set rstGetRegion = qryGetRegion.OpenRecordset()
If rstGetRegion.EOF = False Then
If rstGetRegion!Position = &quot;DLPM&quot; Then
!DISTRICT = rstGetRegion!DISTRICT
Else
![Region] = rstGetRegion![REGION #]
End If
Else
Set qryGetRegion = dbGetRegion.CreateQueryDef(&quot;&quot;, &quot;SELECT Name, Position, Location FROM tblEMailWHSE WHERE Name Like '&quot; & lName & &quot;'&quot;)
Set rstGetRegion = qryGetRegion.OpenRecordset()
If rstGetRegion.EOF = False Then
!loc = rstGetRegion!Location
End If
End If
Else
Dim lName1, lName2, lName3 As String
lName1 = InStr(1, Mailobject.SenderName, &quot;.&quot;) + 1
lName2 = InStr(1, Mailobject.SenderName, &quot;@&quot;)
lName3 = Mid(Mailobject.SenderName, lName1, (lName2 - lName1))
lName = &quot;*&quot; & lName3 & &quot;*&quot;
Set qryGetRegion = dbGetRegion.CreateQueryDef(&quot;&quot;, &quot;SELECT NAME, POSITION, [REGION #], DISTRICT FROM tblEMailLPMs WHERE NAME Like '&quot; & lName & &quot;'&quot;)
Set rstGetRegion = qryGetRegion.OpenRecordset()
If rstGetRegion.EOF = False Then
If rstGetRegion!Position = &quot;DLPM&quot; Then
!DISTRICT = rstGetRegion!DISTRICT
Else
![Region] = rstGetRegion![REGION #]
End If
Else
Set qryGetRegion = dbGetRegion.CreateQueryDef(&quot;&quot;, &quot;SELECT Name, Position, Location FROM tblEMailWHSE WHERE Name Like Like '&quot; & lName & &quot;'&quot;)
Set rstGetRegion = qryGetRegion.OpenRecordset()
End If
End If
If InStr(1, Mailobject.Body, &quot;Code:&quot;) > 0 Then
!code = Mid(Mailobject.Body, (InStr(1, Mailobject.Body, &quot;Code:&quot;)) + 5, 3)
Else
!code = 0
End If
!inboxCC = IIf(Mailobject.CC = &quot;&quot;, &quot; &quot;, Mailobject.CC)
!inboxto = IIf(Mailobject.To = &quot;&quot;, &quot; &quot;, Mailobject.To)
!inboxBody = IIf(Mailobject.Body = &quot;&quot;, &quot; &quot;, Mailobject.Body)
!inboxdatesent = Mailobject.SentOn
.Update
Mailobject.Unread = False
Mailobject.DELETE
End With
Next
Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
Err:
End Function
</code> The hardest questions always have the easiest answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top