Per svariate necessità avrei bisogno di interfacciarmi ad un Outlook ( quindi ovviamente solo su Windows ) e agire sulla rubrica.
Ho cercato un po' di informazioni e ho trovato questo esempio che serve a mandare un email:
uses ComObj;
...
procedure TForm1.Button1Click(Sender: TObject);
const olMailItem=0;
var Mail,Message:variant;
begin
// attach to running outlook
// Mail:=GetActiveOleObject('Outlook.Application');
// open Outlook
Mail:=CreateOleObject('Outlook.Application');
Message:=Mail.CreateItem(olMailItem);
Message.Recipients.Add('first at recipient');
Message.Recipients.Add('second at recipient');
Message.Subject:= 'This is the subject';
Message.Body:= 'Hi from lazarus';
Message.CC:='cc at recipient';
Message.Attachments.Add('C:\lazarus\readme.txt') ;
Message.Send();
end;
Poi suggeriscono di usare le documentazioni per VB/VBA che sono decisamente più facili da trovare e adattarle esempio questo
http://support.microsoft.com/kb/220595/it
Però non ho le costanti, non so se devo aggiungere la libreria "MSOUTL.OLB" come riferimento o cosa, ad esempio si pianta giustamente arrivando al
Set olItem = olApp.CreateItem(olContactItem)
che non trova "olContactItem"
Potrei fare tutto in VB e via, ma se possibile volevo farlo con Lazarus.
Avete qualche esperienza in merito?
Grazie.
le costanti le devi dichiarare tu nella unit
oggi sei fortunato ;)
const
// items
olMailItem = 0;
olAppointmentItem = 1;
olContactItem = 2;
olTaskItem = 3;
olJournalItem = 4;
// folder
olFolderCalendar = 9; // The Calendar folder.
olFolderContacts = 10; // The Contacts folder.
olFolderTasks = 13; // The Tasks folder.
olFolderConflicts = 19; // The Conflicts folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderDeletedItems = 3; // The Deleted Items folder.
olFolderDrafts = 16; // The Drafts folder.
olFolderInbox = 6; // The Inbox folder.
olFolderJournal = 11; // The Journal folder.
olFolderJunk = 23; // The Junk E-Mail folder.
olFolderLocalFailures = 21; // The Local Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderManagedEmail = 29; // The top-level folder in the Managed Folders group. For more information on Managed Folders, see Help in Microsoft Outlook. Only available for an Exchange account.
olFolderNotes = 12; // The Notes folder.
olFolderOutbox = 4; // The Outbox folder.
olFolderSentMail = 5; // The Sent Mail folder.
olFolderServerFailures = 22; // The Server Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderSyncIssues = 20; // The Sync Issues folder. Only available for an Exchange account.
olFolderToDo = 28; // The To Do folder.
olPublicFoldersAllPublicFolders = 18; // The All Public Folders folder in the Exchange Public Folders store. Only available for an Exchange account.
olFolderRssFeeds = 25; // The RSS Feeds folder.
// field type
olText = 1;
// attachments
wdStory = 6;
Ho messo questo:
const
olFolderContacts=10;
...
procedure TfrmMain.Button1Click(Sender: TObject);
var
olApp, olNs, olContacts: OleVariant;
Each: Integer;
begin
olApp:=CreateOleObject('Outlook.Application');
olNs:=olApp.GetNamespace('MAPI');
olNs.Logon;
olContacts:=olNs.GetDefaultFolder(olFolderContacts).Items;
for Each:=1 to olContacts.Count do
begin
ShowMessage(olContacts.Item[Each].FullName);
end;
end;
Se faccio uno ShowMessage di olContacts.Count mi riporta il numero corretto dei contatti ma quando vado a stampare la proprietà FullName mi dice
raised exception class 'EOleSysError' parametro non corretto
lavorare con Ole non è facile...
prova qualcosa del genere e vedi se riesci a leggere i campi:
var
itmContact, itmProperty: OleVariant;
ScanProp: integer;
sName, sValue: string;
begin
...
itmContact:= olContacts.Items[scan];
for ScanProp := 0 to itmContact.ItemProperties.Count - 1 do
begin
itmProperty := itmContact.ItemProperties.Item[ScanProp];
sName := itmProperty.Name;
sValue := VarToStr( itmProperty.Value );
...
Mi dice parametro non corretto già subito su
itmContact:= olContacts.Item[Each];
E se faccio così:
Alla riga:
for ScanProp := 0 to itmContact.ItemProperties.Count - 1 do
Dice:
Method 'ItemProperties' is not supported by automation object