Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use Outlook Automation - Scaning Outlook's Folders and reading Mail Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Jul-03
Category
OLE
Language
Delphi 5.x
Views
192
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Vladimir Orlenko

How to serf in Outlook from myself application and read Mail

Answer:

1   unit UScanOutlook;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls, Grids, Outline;
8   const
9     olByValue = 1;
10    olByReference = 4;
11    olEmbeddedItem = 5;
12    olOLE = 6;
13  
14    olMailItem = 0;
15    olAppointmentItem = 1;
16    olContactItem = 2;
17    olTaskItem = 3;
18    olJournalItem = 4;
19    olNoteItem = 5;
20    olPostItem = 6;
21  
22    olFolderDeletedItems = 3;
23    olFolderOutbox = 4;
24    olFolderSentMail = 5;
25    olFolderInbox = 6;
26    olFolderCalendar = 9;
27    olFolderContacts = 10;
28    olFolderJournal = 11;
29    olFolderNotes = 12;
30    olFolderTasks = 13;
31  
32  type
33    TItem = class(TObject)
34      Letter: OleVariant;
35        name: string;
36    end;
37    TForm1 = class(TForm)
38      oline_outlook: TOutline;
39      Button8: TButton;
40      procedure Button8Click(Sender: TObject);
41      procedure oline_outlookDblClick(Sender: TObject);
42      procedure FormCreate(Sender: TObject);
43      procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
44    private
45      { Private declarations }
46    public
47      { Public declarations }
48      OlApp, NameSpace, root: OleVariant;
49      List: Tlist;
50      Item: TItem;
51      icount: integer;
52    end;
53  
54  var
55    Form1: TForm1;
56  
57  implementation
58  uses ComObj;
59  {$R *.DFM}
60  
61  procedure TForm1.Button8Click(Sender: TObject);
62    procedure scan(ol: TOutline; root: OleVariant; s: string);
63    var
64      i, j, k: integer;
65      bcount, rcount: integer;
66      branch, MAPIFolder: olevariant;
67      line: string;
68    begin
69      line := '';
70      rcount := root.count;
71      for i := 1 to rcount do
72      begin
73        line := s + root.item[i].name;
74        ol.Lines.Add(line);
75        List.Add(TItem.Create);
76        Item := List.items[List.count - 1];
77        Item.name := 'Folder';
78        branch := root.item[i].folders;
79        bcount := branch.count;
80        MAPIFolder := Namespace.GetFolderFromId(root.item[i].EntryID,
81          root.item[i].StoreID);
82        if MAPIFolder.Items.count > 0 then
83          for j := 1 to MAPIFolder.Items.count do
84          begin
85            ol.Lines.Add(s + ' ' + MAPIFolder.Items[j].subject);
86            List.Add(TItem.Create);
87            Item := List.items[List.count - 1];
88            Item.name := 'File';
89            Item.Letter := MAPIFolder.Items[j];
90          end;
91        if bcount > 0 then
92        begin
93          scan(ol, branch, s + ' ');
94        end;
95      end;
96    end;
97  begin
98    oline_outlook.Lines.Clear;
99    OlApp := CreateOleObject('Outlook.Application');
100   Namespace := OlApp.GetNameSpace('MAPI');
101   root := Namespace.folders;
102   scan(oline_outlook, root, '');
103 end;
104 
105 procedure TForm1.oline_outlookDblClick(Sender: TObject);
106 begin
107   Item := List.items[oline_outlook.SelectedItem - 1];
108   if Item.name = 'File' then
109     ShowMessage(Item.Letter.Body);
110 end;
111 
112 procedure TForm1.FormCreate(Sender: TObject);
113 begin
114   List := TList.Create;
115   Item := TItem.Create;
116   icount := 0;
117 end;
118 
119 procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
120 var
121   i: integer;
122 begin
123   for i := List.Count - 1 downto 0 do
124   begin
125     Item := List.Items[i];
126     Item.Free;
127   end;
128   List.Free;
129 end;
130 
131 end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC