BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Accessing Outlook Contact folder...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical
View previous topic :: View next topic  
Author Message
G. Bradley MacDonald
Guest





PostPosted: Fri Aug 29, 2003 6:45 pm    Post subject: Re: Accessing Outlook Contact folder... Reply with quote



In article <3f4f7a4b (AT) newsgroups (DOT) borland.com>, [email]aohlsson (AT) borland (DOT) com[/email]
says...
Quote:
The OutLookApplication and ContactItem components (among others) are on
the Server tab.
Use those to retrieve the contact info.

Then use the Indy components for sending the emails.

There is an example of automating Word 97 (works for 2K as well) in the
Delphi 7 samples
(written by yours truly) and doing it with OutLook should be very
similar. I'm also trapping
events from Word in the demo.

The Indy components also come with plenty of samples.


Anders - a very good idea. thank you.


Bradley

Back to top
Asaf
Guest





PostPosted: Sat Aug 30, 2003 10:12 am    Post subject: Re: Accessing Outlook Contact folder... Reply with quote



First place 2 contorls from the Servers VCL tab on your form:
TOutlookApplication
TContactItem

The below code is the code form my Form so you can take the code you need to
connect to outlook:
Best Regards,
Asaf

unit frmOutlookU;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Outlook2000, OleServer, CheckLst, ComCtrls,
ToolWin, ImgList, Menus, Grids, BaseGrid, AdvGrid, QExport, QExportXLS,
ShellAPI,
FormHints;

type
TfrmOutlook = class(TForm)
Panel1: TPanel;
GroupBox1: TGroupBox;
Outlook: TOutlookApplication;
Contact: TContactItem;
cbContactsFolders: TComboBox;
Panel2: TPanel;
GroupBox2: TGroupBox;
clbContacts: TCheckListBox;
ImageList1: TImageList;
ToolBar1: TToolBar;
tlbExit: TToolButton;
tlbHelp: TToolButton;
StatusBar1: TStatusBar;
Panel3: TPanel;
GroupBox4: TGroupBox;
GroupBox6: TGroupBox;
tlbSaveList: TToolButton;
ToolButton2: TToolButton;
tlbDistList: TToolButton;
strGridExcelNumbers: TAdvStringGrid;
strGridWrongNumbers: TAdvStringGrid;
tlbDeleteContact: TToolButton;
tlbClearGrids: TToolButton;
QExportXLS1: TQExportXLS;
tlbCreateNewDistList: TToolButton;
svDlgExcel: TSaveDialog;
tlbCheckList: TToolButton;
tlbUnCheckList: TToolButton;
ToolButton1: TToolButton;
FormHints1: TFormHints;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cbContactsFoldersCloseUp(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cbContactsFoldersChange(Sender: TObject);
procedure tlbExitClick(Sender: TObject);
procedure tlbDistListClick(Sender: TObject);
procedure tlbDeleteContactClick(Sender: TObject);
procedure tlbClearGridsClick(Sender: TObject);
procedure tlbSaveListClick(Sender: TObject);
procedure tlbCreateNewDistListClick(Sender: TObject);
procedure tlbCheckListClick(Sender: TObject);
procedure tlbUnCheckListClick(Sender: TObject);
procedure tlbHelpClick(Sender: TObject);
private
ContactsFolder, otlFolders: MAPIFolder;
NmSpace: NameSpace;
otlFolderEntryID, otlFolderStoreID: array of WideString;
SortedItems: Items;
function CheckValidNumber(sPhoneNumber: string): Boolean;

{ Private declarations }
public
{ Public declarations }
end;

var
frmOutlook: TfrmOutlook;
flgFixedRowAdded: Boolean = false;
implementation

uses frmMainU, ToolsU;

{$R *.dfm}

procedure TfrmOutlook.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Contact.Disconnect;
NmSpace.Logoff;
Outlook.Quit;

Self.Release;
end;

procedure TfrmOutlook.FormCreate(Sender: TObject);
var
i: integer;
begin
strGridExcelNumbers.ColWidths[1] := 175;
strGridWrongNumbers.ColWidths[1] := 175;

Outlook.Connect;
NmSpace := Outlook.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);

ContactsFolder := NmSpace.GetDefaultFolder(olFolderContacts);

// cbContactsFolders.Items.Add(ContactsFolder.Folders.Item(1).Name)

SetLength(otlFolderEntryID, ContactsFolder.Folders.Count +1);
SetLength(otlFolderStoreID, ContactsFolder.Folders.Count +1);

cbContactsFolders.Items.Add('ראשי');
for I := 1 to ContactsFolder.Folders.Count do
begin
cbContactsFolders.Items.Add(ContactsFolder.Folders.Item(i).Name);
otlFolderEntryID[i] := ContactsFolder.Folders.Item(i).EntryID;
otlFolderStoreID[i] := ContactsFolder.Folders.Item(i).StoreID;
end;

//Move 'ראשי' to be the first in the list after the sort
cbContactsFolders.Items.Move(cbContactsFolders.Items.IndexOf('ראשי'),0);
cbContactsFolders.ItemIndex := 0;
cbContactsFolders.OnChange(Self);
end;

procedure TfrmOutlook.cbContactsFoldersChange(Sender: TObject);
var
i: Integer;
begin
GroupBox2.Caption := 'רשימת אנשי קשר לתיקיה: ' + cbContactsFolders.Text;
clbContacts.Clear;
if (cbContactsFolders.ItemIndex = 0) then
otlFolders := ContactsFolder
else
begin
//for i := Low(otlFolderEntryID) to High(otlFolderEntryID) do
for i := 1 to ContactsFolder.Folders.Count do
begin
if (ContactsFolder.Folders.Item(i).Name = cbContactsFolders.Text) then
otlFolders := ContactsFolder.Folders.Item(i);
end;
end;
//otlFolders := ContactsFolder.Folders.Item(cbContactsFolders.ItemIndex);
//otlFolders :=
NmSpace.GetFolderFromID(otlFolderEntryID[cbContactsFolders.ItemIndex],
//otlFolderStoreID[cbContactsFolders.ItemIndex]);

{
otlFolders := ContactsFolder.Folders.Item(2);
ShowMessage(otlFolders.Name);
ContactsFolder := NmSpace.GetFolderFromID(otlFolders.EntryID,
otlFolders.StoreID);
}

//otlFolders.Items.Sort('[LastName]', 1);
SortedItems := otlFolders.Items;
SortedItems.Sort('[FirstName]', 2);

{
for i := 1 to otlFolders.Items.Count do
clbContacts.Items.Add((otlFolders.Items.Item(i) as ContactItem).FirstName
+
' ' + (otlFolders.Items.Item(i) as ContactItem).LastName +
' ' + (otlFolders.Items.Item(i) as ContactItem).MobileTelephoneNumber);
clbContacts.Sorted := True; // do this once after the names are added, for
speed
}

for i := 1 to SortedItems.Count do
clbContacts.Items.Add((SortedItems.Item(i) as ContactItem).FirstName +
' ' + (SortedItems.Item(i) as ContactItem).LastName +
' ' + (SortedItems.Item(i) as ContactItem).MobileTelephoneNumber);
// clbContacts.Sorted := True; // do this once after the names are added,
fo


// ContactNamesCombo.ItemIndex := 0;
//LoadComboItem;
end;

procedure TfrmOutlook.tlbExitClick(Sender: TObject);
begin
Self.Close;
end;

procedure TfrmOutlook.tlbDistListClick(Sender: TObject);
var
I, iIndex: Integer;
grdFind: TPoint;
strName, strMobile: string;
saveCursor: TCursor;
begin
//strGridExcelNumbers.RowCount := strGridExcelNumbers.RowCount + 1;
//strGridExcelNumbers.ColWidths[1] := strtoint(edit1.text);
saveCursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
for I := 0 to clbContacts.Items.Count - 1 do
begin
if clbContacts.Checked[i] then
begin
iIndex := I + 1;
strMobile := (SortedItems.Item(iIndex) as
ContactItem).MobileTelephoneNumber;
strName := (SortedItems.Item(iIndex) as ContactItem).FirstName + ' ' +
(SortedItems.Item(iIndex) as ContactItem).LastName;
if not CheckValidNumber(strMobile) then
begin
with strGridWrongNumbers do
begin
grdFind := FindFirst(strName, []); //There is no need for settings
if not (grdFind.x>=0) then
begin
RowCount := RowCount +1;
Cells[0, RowCount - 1] := strMobile;
Cells[1, RowCount - 1] := strName;
end;
end;
end
else
begin
with strGridExcelNumbers do
begin
grdFind := FindFirst(strMobile, []); //There is no need for
settings
if not (grdFind.x>=0) then
begin
RowCount := RowCount +1;
Cells[0, RowCount - 1] := strMobile;
Cells[1, RowCount - 1] := strName;
end;
end;
end;
end;
end;

if not flgFixedRowAdded then
begin
with strGridExcelNumbers do
begin
if (RowCount <> 1) then
begin
FixedRows := 1;
Cells[0,0] := 'סלולארי';
Cells[1,0] := 'נמען';
SortByColumn(1);
end;
end;

with strGridWrongNumbers do
begin
if (RowCount <> 1) then
begin
FixedRows := 1;
Cells[0,0] := 'סלולארי';
Cells[1,0] := 'נמען';
SortByColumn(1);
end;
end;
end;
finally
Screen.Cursor := saveCursor;
end; // try/finally
end;

end.

"G. Bradley MacDonald" <bradley_A (AT) T_telus_DOT (DOT) _net> wrote

Quote:
I have a need to email various of the people who have purchased my
shareware which is written in Delphi. Right now I have all my customers
in Outlook - in the Contacts.

I cannot email more than 50 at a time - restrictions from my ISP and web
site providers - so I need a way to automate mailing from Outlook.

I would like to email to all the entries that have a particular catagory
- and then send each of them an email about the new Beta.

Has anyone done anything like this? Are their compponents out there
that would enable me to do it - without a huge learning curve? Are
their products that will allow me to do this?

Bradley MacDonald
bradley_AT_telus_DOT_net



Back to top
G. Bradley MacDonald
Guest





PostPosted: Sun Aug 31, 2003 3:44 am    Post subject: Re: Accessing Outlook Contact folder... Reply with quote



Thank you for the code!!

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.