Solved

Do Outlook-Items have Individual IDs?

Posted on 2001-06-13
2
784 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 330
Simple Delphi Question 9 96
Delphi: ForceDirectory plain function 7 42
Microsoft Access 97 and Delphi XE2 9 58
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 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