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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to point to a specific email in Outlook with EntryID 1

Status
Not open for further replies.

freddiekg

Programmer
Oct 13, 2009
25
0
0
MY
Dear all,

I have a DBF that stores all the emails' fields (entryid, sendername...etc.). The VFP app that I build so far can display those fields in a grid and also let the user query the results by certain criteria (e.g. sendername, receivedtime...etc.) Now, I like to add a new feature for the user to view the actual email in Outlook when they click on the email record in the grid.

So, the following needs to happen when the user click on the record:
(1) Open the Outlook application,
(2) Display the email by passing the "EntryID" to the Outlook.

Is this possible?

Thanks in advance.
Freddie
 
Freddie,

loOutlook = createobject("outlook.application")
loNS = loOutlook.getnamespace("MAPI")
loItem = loNS.getitemfromid(entryid)
loitem.display(.f.)


Nigel
 
make that

=loitem.display(.f.)

(i.e. with the = sign)

without can give a 'parameter not optional' error.

n
 
Dear Nigel,

Thanks for your help, but I got an error when I ran the code, I got an "OLE IDispatch exception code 4096 from Microsoft Office Outlook: Could not open the item. Try again." at the 3rd line of your code below.

loOutlook = CREATEOBJECT("outlook.application")
loNS = loOutlook.getnamespace("MAPI")
loItem = loNS.getitemfromid(entryid)
=loitem.display(.f.)

My sample EntryID looks like this:
000000009EA88203D0F096469FFEB5714311E3F5040B2000

Do I have to identify the folder id or something too?

Thanks in advance.
Regards,
Freddie
 
Freddie,

might that original item has been moved to another folder since you stored the entryid ?

Items get a new entryid when they are moved to a new folder.

One way to get around that is, at the point you store the entryid, to add a user property to the item with the PK of your table.

Then if the entryid doesn't work traverse the folders looking for the primary key.... it's a bit slow but it gives you the chance to get the new entryid for subsequent opening.

Something like...


when saving the entryid...
loItem.UserProperties("FreddiePK").VALUE = journal.journalid
=loItem.save()


then if you can't retrieve it (untested)...

*!* MS Outlook constants
#DEFINE olFolderCalendar 9
#DEFINE olFolderContacts 10
#DEFINE olFolderDeletedItems 3
#DEFINE olFolderInBox 6
#DEFINE olFolderJournal 11
#DEFINE olFolderNotes 12
#DEFINE olFolderOutBox 4
#DEFINE olFolderSentMail 5
#DEFINE olFolderTask 13
#DEFINE olPublicFoldersAllPublicFolders 18

#DEFINE olContactItem 2
#DEFINE olAppointmentItem 1
#DEFINE olTaskItem 3

#DEFINE olText 1
#DEFINE olNumber 3
#DEFINE olCurrency 14
#DEFINE olDateTime 5
#DEFINE olBoolean 6
loOutlook = createobject("outlook.application")
loNS = loOutlook.getnamespace('MAPI')
loDefaultFolder=loNS.GetDefaultFolder(olFolderInBox)
loItems = loDefaultFolder.items
*!* this bit just makes sure the PK is known to the folder we are searching so the find always works
IF loItems.COUNT > 0
loItem = loItems.ITEM(1)
ELSE
loItem = loItems.ADD()
ENDIF
loItem.UserProperties.ADD("FreddiePK",olNumber)
=loItem.SAVE()
loItem = NULL
*!*

loItem = loItems.FIND('[FreddiePK]='+TRANSFORM(journal.journalid))
if !isnull(loitem)
replace entryid with loitem.entryid &&remember new id for next time
endif

to traverse the folders put the search inside a loop

FOR EACH loFolder IN loDefaultFolder.folders
ENDFOR



hth

Nigel


 
sorry.. it's late.

that comment should say

*!* this bit just makes sure the userproperty freddiePK is known to the folder we are searching so the find doesn't give an error

and journal.journalid would be the table and primary key where you are saving these entryids.

n
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top