Author: Mike Shkolnik
How can I create a new message in MS Outlook using OLE?
Answer:
1 const2 olMailItem = 0;
3 var4 Outlook: OLEVariant;
5 MailItem: Variant;
6 begin7 try8 Outlook := GetActiveOleObject('Outlook.Application');
9 except10 Outlook := CreateOleObject('Outlook.Application');
11 end;
12 13 MailItem := Outlook.CreateItem(olMailItem);
14 MailItem.Recipients.Add('mshkolnik@scalabium.com');
15 MailItem.Subject := 'your subject';
16 MailItem.Body := 'Welcome to my homepage: http://www.scalabium.com';
17 MailItem.Attachments.Add('C:\Windows\Win.ini');
18 MailItem.Send;
19 20 Oulook := Unassigned;
21 end;
I can save tasks and contacts to Outlook using OLE, but I need to be able to
synchronize existing contacts. Do you have any ideas?
I think that you have a two methods with solutions
1.
22 var23 app, NameSpace, Contact: OLEVariant;
24 begin25 app := CreateOleObject(`Outlook.Application`);
26 NameSpace := app.GetNameSpace(`MAPI`);
27 Contact := NameSpace.GetItemFromID(EntryIDItem, EntryIDStore)
28 {...}29 end;
2. also you can navigate by contract items and compare the IDs. I understood that
it`s not a good solution but without errors:)
30 app := CreateOleObject(`Outlook.Application`);
31 Contacts := app.GetDefaultFolder(10); {olFolderContacts}32 for i := 0 to Items.Count - 1 do33 begin34 Contact := Items[i];
35 {...}36 end;
How can I format the content of the body text to be HTML?
If you want to have html formatted message, use HTMLBody property instead Body. But
not that this property is available starting from Outlook 98 only.
I need to parse through a certain folder's messages and put some data into a
database based off what is in the messages. Suggestions?
Check my articles about MS Outlook programming:
http://www.scalabium.com/faq/dct0120.htm
http://www.scalabium.com/faq/dct0121.htm
http://www.scalabium.com/faq/dct0123.htm
and download a Delphi sample for these articles:
http://www.scalabium.com/faq/delphioutlook.zip
I try to execute this procedure in my program, i get the following error: project
project1 raised exception class EOleSysError with message 'CoInitialize not
called'.
You must call the OLEInitialize(nil) procedure from ComCtrls.pas unit. Some third-party suites unload this library from memory. Also additioanlly you must call it from every your thread if you'll use an OLE from this thread.