Solved

Do Outlook-Items have Individual IDs?

Posted on 2001-06-13
2
782 Views
Last Modified: 2012-06-27
Can someone please tell me, if outlook-items, that i
create from delphi, have individual ids?
if they have one, how do i manage to get them?

thanks for your help.
0
Comment
Question by:olli_braun
2 Comments
 
LVL 1

Accepted Solution

by:
PeterZG earned 100 total points
ID: 6235448
Based on Microsoft Outlook (I believe that its similar if not identical in Outlook Express).

Every folder has for IDs: EntryID, StoreID, ParentEntryID and StoreEntryID.
Every other item (mail, contact, appointment...) has two IDs: EntryID and StoreID.


Here you have a code which I wrote some time ago, while learning access to M$ Exchange from Delphi. Its just pas file, but hopefully will give you idea how to access those IDs.

It was written in Delphi 5 using imported Outlook.tlb.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, OleServer, ComCtrls, StdCtrls, Outlook8, TreeNT, OleCtrls,
  ExtCtrls, RzTreeVw, treelist, advpanel, rtflabel, VirtualTrees,
  Outlook_TLB;

type
  PFolderRec = ^TFolderRec;
  TFolderRec = record
    EntryID       : WideString;
    StoreID       : WideString;
    ParentEntryID : WideString;
    ParentStoreID : WideString;
  end;

  PEmailRec = ^TEmailRec;
  TEmailRec = record
    EntryID : WideString;
    StoreID : WideString;
  end;



 
{From MSDN.

' You need the message class to determine the type.
    strMessageClass = oItem.MessageClass

    If (strMessageClass = "IPM.Appointment") Then       ' Calendar Entry.
        Set oAppointItem = oItem
        MsgBox oAppointItem.Subject
        MsgBox oAppointItem.Start
    ElseIf (strMessageClass = "IPM.Contact") Then       ' Contact Entry.
        Set oContactItem = oItem
        MsgBox oContactItem.FullName
        MsgBox oContactItem.Email1Address
    ElseIf (strMessageClass = "IPM.Note") Then          ' Mail Entry.
        Set oMailItem = oItem
        MsgBox oMailItem.Subject
        MsgBox oMailItem.Body
    ElseIf (strMessageClass = "IPM.Activity") Then      ' Journal Entry.
        Set oJournalItem = oItem
        MsgBox oJournalItem.Subject
        MsgBox oJournalItem.Actions
    ElseIf (strMessageClass = "IPM.StickyNote") Then    ' Notes Entry.
        Set oNoteItem = oItem
        MsgBox oNoteItem.Subject
        MsgBox oNoteItem.Body
    ElseIf (strMessageClass = "IPM.Task") Then          ' Tasks Entry.
        Set oTaskItem = oItem
        MsgBox oTaskItem.DueDate
        MsgBox oTaskItem.PercentComplete
    End If
}


  TForm1 = class(TForm)
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    lblFolderName: TLabel;
    lblEntryID: TLabel;
    lblStoreID: TLabel;
    lblParentName: TLabel;
    lblParentEntryID: TLabel;
    lblParentStoreID: TLabel;
    OutlookApp: TOutlookApplication;
    Panel2: TPanel;
    TreeNT1: TTreeNT;
    TreeList1: TTreeList;
    AdvPanel1: TAdvPanel;
    Label7: TLabel;
    Label8: TLabel;
    SpeedButton2: TSpeedButton;
    Label9: TLabel;
    VT1: TVirtualStringTree;
    Label10: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton1Click(Sender: TObject);
    procedure TreeNT1Click(Sender: TObject);
    procedure EnumFolders(aFolder: MAPIFolder; aNode: TTreeNTNode);
    procedure TreeList1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


var
   MAPI : NameSpace;

   aRecord : PFolderRec;
   aEmailRecord : PEmailRec;

   prev_selected : TTreeNTNode;
   EmailItem   : variant;

   currentID : WideString;

   doc: TDocumentItem;

   //oItem:




procedure TForm1.EnumFolders(aFolder: MAPIFolder; aNode: TTreeNTNode);
var
   i: integer;
   newNode: TTreeNTNode;
begin
     if (aFolder.Folders.Count > 0)
     then begin
               for i:=1 to aFolder.Folders.Count do
               begin
                    if TreeNT1.Items.FindNode([ffData], '', Pointer(PFolderRec(aFolder.Folders.Item(i))^.EntryID)) = nil
                    then begin
                              New(aRecord);
                              aRecord^.EntryID := aFolder.Folders.Item(i).EntryID;
                              aRecord^.StoreID := aFolder.Folders.Item(i).StoreID;
                              aRecord^.ParentEntryID := aFolder.EntryID;
                              aRecord^.ParentStoreID := aFolder.StoreID;
                              newNode := TreeNT1.Items.AddChildObject(aNode, aFolder.Folders.Item(i).Name, aRecord);
                              EnumFolders(aFolder.Folders.Item(i), newNode);
                         end
               end

          end
     else begin
               aFolder := MAPI.GetFolderFromID(aRecord^.ParentEntryID, aRecord^.ParentStoreID)
          end
end;


procedure TForm1.SpeedButton1Click(Sender: TObject);
var
   i: integer;
   newNode: TTreeNTNode;
   aFolder: MAPIFolder;
begin
   TreeNT1.Items.BeginUpdate;
   TreeNT1.Items.Clear;
     for i:=1 to MAPI.Folders.Count
     do begin
             aFolder := MAPI.Folders.Item(i);
             New(aRecord);
             aRecord^.EntryID := aFolder.EntryID;
             aRecord^.StoreID := aFolder.StoreID;
             aRecord^.ParentEntryID := '';
             aRecord^.ParentStoreID := '';
             newNode := TreeNT1.Items.AddObject(nil, aFolder.Name, aRecord);
             EnumFolders(aFolder, newNode);
        end;
   TreeNT1.Items.EndUpdate;
   prev_selected := nil;


end;






procedure TForm1.FormShow(Sender: TObject);
begin
     OutlookApp.Connect;
     MAPI := OutlookApp.GetNamespace('MAPI');

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     OutlookApp.Disconnect
end;



procedure TForm1.TreeNT1Click(Sender: TObject);
var
   aFolder: MAPIFolder;
   i,j : integer;
   email_from,
   subject     : WideString;
   rec_date    : TDateTime;
   email_data  : TStringList;
   FolderItem  : IDispatch;
   a           : MailItem;
   AppItem     : AppointmentItem;
   ConItem     : ContactItem;
begin
     if TreeNT1.Selected <> prev_selected then
     if TreeNT1.Selected <> nil
     then begin
             lblFolderName.Caption    := TreeNT1.Selected.Text;
             lblEntryID.Caption       := PFolderRec(TreeNT1.Selected.Data)^.EntryID;
             lblStoreID.Caption       := PFolderRec(TreeNT1.Selected.Data)^.StoreID;
             lblParentEntryID.Caption := PFolderRec(TreeNT1.Selected.Data)^.ParentEntryID;
             lblParentStoreID.Caption := PFolderRec(TreeNT1.Selected.Data)^.ParentStoreID;

             aFolder := MAPI.GetFolderFromID(PFolderRec(TreeNT1.Selected.Data)^.EntryID,
                                             PFolderRec(TreeNT1.Selected.Data)^.StoreID);

             Label8.Caption := aFolder.DefaultMessageClass;


             TreeList1.Items.BeginUpdate;
             TreeList1.Items.Clear;
             //aEmailRecord := nil;
             for i:=1 to aFolder.Items.Count
             do begin
                     EmailItem := aFolder.Items;
                     New(aEmailRecord);
                     aEmailRecord^.EntryID := EmailItem.Item(i).EntryID;
                     aEmailrecord^.StoreID := PFolderRec(TreeNT1.Selected.Data)^.StoreID;
                     TreeList1.Items.AddChildObject(nil, EmailItem.Item(i).Subject + ';' + ';' + ';', aEmailRecord)
                end;
             TreeList1.Items.EndUpdate
          end
     {else begin
               TreeList1.Items.BeginUpdate;
               TreeList1.Items.Clear;
               TreeList1.Items.EndUpdate
          end;}

     //AdvListView1.Clear;
     //AdvListView1.Items.BeginUpdate;
     {for i:= 1 to aFolder.Items.Count do
     begin
          Email.ConnectTo (aFolder.Items.Item(i) as MailItem);
          email_from := Email.ReceivedByName;
          subject    := Email.Subject;
          rec_date   := Email.ReceivedTime;
          email_data := TStringList.Create;
          email_data.Add(email_from);
          email_data.Add(subject);
          email_data.Add(DateToStr(rec_date));
          //ListView1.Items.Add.SubItems.Add(email_from);
          ColumnListBox1.ListBoxItems.Add;
          for j:=0 to email_data.Count-1 do
          ColumnListBox1.ListBoxItems.Items[j].Strings := email_data;
          email_data.Free

          //AdvListView1.Items.Add.SubItems.Add(email_from)

     end; }
     //AdvListView1.Items.EndUpdate;
end;

procedure TForm1.TreeList1Click(Sender: TObject);
var
   email_body: WideString;
   b : variant;
begin
     b := MAPI.GetItemFromID(PEmailRec(TreeList1.Selected.Data)^.EntryID,
                        PEmailRec(TreeList1.Selected.Data)^.StoreID);

     Label9.Caption := b.MessageClass;

     //Memo1.Clear;
     //Memo1.Lines.BeginUpdate;

     {MAPI.GetItemFromID.  (PEmailRec(TreeList1.Selected.Data)^.EntryID,
                        PEmailRec(TreeList1.Selected.Data)^.StoreID);

     //Label9.Caption := b.Name;
     Label10.Caption := IntToStr(b.Type_);

     AdvPanel1.Text := b.Body;
     Label7.Caption := b.Body;

    //Memo1.Lines.Add(b.Body);
     //Memo1.Lines.EndUpdate; }
end;


end.



The code may be a bit messy, but it was pure testing enviroment, so I left previous stuff as well.

regards,
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9286044
olli_braun,
No comment has been added lately (798 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to PeterZG http:#6235448

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

DragonSlayer
EE Cleanup Volunteer
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

10 Experts available now in Live!

Get 1:1 Help Now