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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.