Embedding Images in Outlook email via Delphi

R

Rudy Hentzen

Hi,

I know this is a VB Group, however, i am at a brick wall now. Essentially i
am trying to send an email with an Embedded image via Outlook.

I have been told that this cannot be done via the Outlook Object Model and
that i should use CDO or Extended MAPI. I got some VB Code from
http://www.outlookcode.com/d/code/htmlimg.htm and tried to translate it to
Delphi code (see below). I also have an EE thread
(http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23938025.html.) also and will update either accordingly when i have a solution.

So far i have created a type library to the CDO.dll and have managed to get
the image attached but cannot get it embedded.

Test Code

procedure TForm1.Button1Click(Sender: TObject);
var
objApp, l_Msg, colAttach, l_Attach, oSession, oMsg, colFields, oField,
oAttachs, oAttach : OLEVariant;
strEntryID : String;
begin
objApp := CreateOLEObject('Outlook.Application');
l_Msg := objApp.CreateItem(olMailItem);
colAttach := l_Msg.Attachments;
l_attach := colAttach.Add('C:\logo.jpg', olByValue, 1, 'logo.jpg');
l_Msg.Close(olSave);

strEntryID := l_Msg.EntryID;
l_Msg := NULL;
colAttach := NULL;
l_attach := NULL;

oSession := CreateOleObject('MAPI.Session');
oSession.Logon('', '', False, False);
oMsg := oSession.GetMessage(strEntryID);
oAttachs := oMsg.Attachments;
oAttach := oAttachs.Item[1];
colFields := oAttach.Fields;
oField := colFields.Add(CdoPR_ATTACH_MIME_TAG, 'image/jpeg');
oField := colFields.Add($3712001E, 'myident');
oMsg.Fields.Add('{0820060000000000C000000000000046}0x8514', 11, True);
oMsg.Update;
l_Msg := objApp.GetNamespace('MAPI').GetItemFromID(strEntryID);
l_Msg.HTMLBody := '<IMG align=baseline border=0 hspace=0 src=cid:myident>';
l_Msg.Close(olSave);
l_Msg.Display(False);
end;

Many thanks
Rudy
 
Joined
Feb 6, 2009
Messages
1
Reaction score
0
Hi Rudy

Have you found the solution to this? If so, please share it on this site.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top