T
Tomski
Hello!
I've been trying to implement sample code #1 from
http://www.outlookcode.com/d/code/htmlimg.htm and it doesn't work for me.
I use Delphi and Outlook 2000.
I'm successfully logged on. OLMain is a global object:
OLMain.OLS := CoApplication_.Create;
OLMain.NS := OLS.GetNamespace('MAPI');
OLMain.NS.Logon(sUser, sPass, true, true);
....
I add mail:
FEmail := MailItem(OLMain.Outbox.Items.Add(olMailItem));
Set some properties....
....
Now I'm trying to embed pictures:
oSession := MAPI_TLB._Session(CreateOLEObject('MAPI.Session'));
try
sPass := CRMEx.GetLoginData(sUser, sServer); // obtain logon
information
try
if FindFirst(FDir + '*.*', faAnyFile-faDirectory-faVolumeID, sr) =
0 then begin // get all images from certain dir
repeat
if ExtractFileExt(sr.Name) <> '.html' then begin
vAtts := FEmail.Attachments;
vAtt := vAtts.Add(OGetUniversalName(FDir + sr.Name),
olByValue, 1, ExtractFileName(FDir + sr.Name));
FEmail.Close(olSave);
eid := FEmail.EntryID;
sid := OLMain.WorkFolder.StoreID;
FEmail := nil;
vAtts := nil;
vAtt := nil;
try
oSession.Logon(sUser, sPass, true, true, 0, true,
EmptyParam); // I logon to the existing session
try
oMsg := Unassigned;
oMsg := oSession.GetMessage(eid, sid); // here comes an
exception:
// The file C:\Documents and Settings\Administrator\Local
Settings\Application Data\Microsoft\Outlook\mailbox.pst
// is in use and could not be accessed. Close any application that is using
this file, and then try again.
// [Personal Folders - [MAPI_E_EXTENDED_ERROR(80040119)]]
oAttachs := oMsg.Attachments;
oAttach := oAttachs.Item(oAttachs.Count);
colFields := oAttach.Fields;
oField := colFields.Add(CdoPR_ATTACH_MIME_TAG,
'image/jpeg');
oField := colFields.Add(CdoPR_ATTACH_CONTENT_ID,
EncodeBase64(sr.Name));
//HideAttachments
oMsg.Fields.Add('{0620080000000000C000000000000046}0x8514', vbBoolean,
True);
oMsg.Update;
sTresc := StringReplace(sTresc, sr.Name,
'cid:'+EncodeBase64(sr.Name), [rfIgnoreCase, rfReplaceAll]); //html body
except
on E: Exception do
ErrMsg(E.ClassName, E.Message);
end;
finally
FEmail := MailItem(OLMain.Namespace.GetItemFromID(eid,
sid));
oField := Unassigned;
colFields := Unassigned;
oMsg := Unassigned;
oSession.Logoff;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
FEmail.HtmlBody := sTresc;
finally
end;
finally
oSession := nil;
end;
Do I have to OLMain.NS.Logoff ?
I've been trying to implement sample code #1 from
http://www.outlookcode.com/d/code/htmlimg.htm and it doesn't work for me.
I use Delphi and Outlook 2000.
I'm successfully logged on. OLMain is a global object:
OLMain.OLS := CoApplication_.Create;
OLMain.NS := OLS.GetNamespace('MAPI');
OLMain.NS.Logon(sUser, sPass, true, true);
....
I add mail:
FEmail := MailItem(OLMain.Outbox.Items.Add(olMailItem));
Set some properties....
....
Now I'm trying to embed pictures:
oSession := MAPI_TLB._Session(CreateOLEObject('MAPI.Session'));
try
sPass := CRMEx.GetLoginData(sUser, sServer); // obtain logon
information
try
if FindFirst(FDir + '*.*', faAnyFile-faDirectory-faVolumeID, sr) =
0 then begin // get all images from certain dir
repeat
if ExtractFileExt(sr.Name) <> '.html' then begin
vAtts := FEmail.Attachments;
vAtt := vAtts.Add(OGetUniversalName(FDir + sr.Name),
olByValue, 1, ExtractFileName(FDir + sr.Name));
FEmail.Close(olSave);
eid := FEmail.EntryID;
sid := OLMain.WorkFolder.StoreID;
FEmail := nil;
vAtts := nil;
vAtt := nil;
try
oSession.Logon(sUser, sPass, true, true, 0, true,
EmptyParam); // I logon to the existing session
try
oMsg := Unassigned;
oMsg := oSession.GetMessage(eid, sid); // here comes an
exception:
// The file C:\Documents and Settings\Administrator\Local
Settings\Application Data\Microsoft\Outlook\mailbox.pst
// is in use and could not be accessed. Close any application that is using
this file, and then try again.
// [Personal Folders - [MAPI_E_EXTENDED_ERROR(80040119)]]
oAttachs := oMsg.Attachments;
oAttach := oAttachs.Item(oAttachs.Count);
colFields := oAttach.Fields;
oField := colFields.Add(CdoPR_ATTACH_MIME_TAG,
'image/jpeg');
oField := colFields.Add(CdoPR_ATTACH_CONTENT_ID,
EncodeBase64(sr.Name));
//HideAttachments
oMsg.Fields.Add('{0620080000000000C000000000000046}0x8514', vbBoolean,
True);
oMsg.Update;
sTresc := StringReplace(sTresc, sr.Name,
'cid:'+EncodeBase64(sr.Name), [rfIgnoreCase, rfReplaceAll]); //html body
except
on E: Exception do
ErrMsg(E.ClassName, E.Message);
end;
finally
FEmail := MailItem(OLMain.Namespace.GetItemFromID(eid,
sid));
oField := Unassigned;
colFields := Unassigned;
oMsg := Unassigned;
oSession.Logoff;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
FEmail.HtmlBody := sTresc;
finally
end;
finally
oSession := nil;
end;
Do I have to OLMain.NS.Logoff ?