• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

OLE with Ms Outlook and OLE with Winfax

I have a memo field and two buttons.

When the first button is clicked, I would have to be able to get the contents of the memo field and put it in an e-mail. (so I would have to probably use an OLE object linked to an e-mail facility like MS Outlook)

The second button however would allow me to get the contents of the memo field and send it through winfax.

Can anyone provide a code? would the code have major differences if I code it to link with MS Outlook then later change it to Ms Exchange?
1 Solution
I suppose you know about importing the Outlook type library. (Project | Import Type library, choose Microsoft Outlook* and then create unit). Include it in your uses list.

You can create an usings OLEVARIANT or types from the imported lib.

Here a OLEVariant method:

procedure TForm1.Button1Click(Sender: TObject);
//working code.
objAddressLists, objAddresses, objNS,objDoc : Olevariant;
body,subject : string;
AdresIndex : integer;
//init mailitem
objNS:= FOutlook.GetNamespace('MAPI');
objAddressLists:= objNS.AddressLists;
objAddresses:= objAddressLists.Item(1);
body := 'test';
subject := 'testmail';
adresIndex := 10; // if you have some adress entries offcourse

//send mailitem
objDoc:= FOutlook.CreateItem(olMailItem);
objDoc.Body:= body;
objDoc.To:= objAddresses.AddressEntries.Item(AdresIndex).Address;
objDoc.Subject:= subject;
///// et cetera
///// .....

You could use COM, to create instances from the interfaces of the imported library (sorry for my terminology), in this case you have to add ComObj to your uses list. Then you can do things like:

function BuildItems: boolean;
//not tested code.
mailtje :_MailItem;
folder : MAPIFolder;
//get items
//create new item
mailtje := CreateComObject(CLASS_MailItem) as _MailItem;
mailtje.Body:= 'This is a test e-mail';
mailtje.To_ := 'florisb@satl.com';

OLEvariants / COM; Early binding versus late binding... ....well, if it's just to send one e-mail with a button just choose one method. I would say COM.

You should convert the contents of your memo to a widestring to put it in the body property.

If you change later to Exchange, you'll have to import the exchange library, will be a bit the same story. I don't know exactly.

Hope to give some help,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now