Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2004

Tip: Looking for answers? Try searching our database.

Html emails with attachments

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tomski - 27 Jul 2004 15:11 GMT
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 ?
--
Greetings
Tomski
Tomski - 27 Jul 2004 17:40 GMT
> 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.

.....

The topic should be "Html emails with images" not "attachments"...
Any help appreciated

--
Regards
Tomski
Dmitry Streblechenko \(MVP\) - 27 Jul 2004 17:51 GMT
Do not call Session.Logon in CDO with the NewProfile parameter = true.
Request an existing session (already created by Outlook).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

> Hello!
> I've been trying to implement sample code #1 from
[quoted text clipped - 88 lines]
> Greetings
> Tomski
Tomski - 28 Jul 2004 08:05 GMT
Dmitry Streblechenko (MVP) wrote:
> Do not call Session.Logon in CDO with the NewProfile parameter = true.
> Request an existing session (already created by Outlook).

Thanks Dmitry, but that doesn't work. I've tried both true and false with
same result...

--
Tomski
Dmitry Streblechenko \(MVP\) - 28 Jul 2004 08:17 GMT
The trick is to pick up the existing session, so that the PST provider does
not get loaded twice. Did you try Logon with no parameters at all?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

> Dmitry Streblechenko (MVP) wrote:
> > Do not call Session.Logon in CDO with the NewProfile parameter = true.
[quoted text clipped - 5 lines]
> --
> Tomski
Tomski - 28 Jul 2004 08:28 GMT
Dmitry Streblechenko (MVP) wrote:
> The trick is to pick up the existing session, so that the PST
> provider does not get loaded twice. Did you try Logon with no
> parameters at all?

Yes, I've tried ALL combinations. It doesn't work even if I set only
NewSession := false.

Signature

RegardsTomski

Dmitry Streblechenko \(MVP\) - 28 Jul 2004 20:24 GMT
Then your only other option is to use the MailItem.MAPIOBJECT (which
evaluates to IMessage) either directly using Extended MAPI or indirectly
through Redemption - see
http://www.dimastr.com/redemption/objects.htm#examples and scroll to "Create
an HTML message with an embedded image".

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

> Dmitry Streblechenko (MVP) wrote:
> > The trick is to pick up the existing session, so that the PST
[quoted text clipped - 3 lines]
> Yes, I've tried ALL combinations. It doesn't work even if I set only
> NewSession := false.
Tomski - 29 Jul 2004 09:15 GMT
Dmitry Streblechenko (MVP) wrote:
> Then your only other option is to use the MailItem.MAPIOBJECT (which
> evaluates to IMessage) either directly using Extended MAPI or
> indirectly through Redemption - see
> http://www.dimastr.com/redemption/objects.htm#examples and scroll to
> "Create an HTML message with an embedded image".

Yes, I've just started to do it that way. I'd say I read your mind ;)
Signature

Pozdrawiam
Tomski

Tomski - 28 Jul 2004 08:18 GMT
> Dmitry Streblechenko (MVP) wrote:
>> Do not call Session.Logon in CDO with the NewProfile parameter =
>> true. Request an existing session (already created by Outlook).
>
> Thanks Dmitry, but that doesn't work. I've tried both true and false
> with same result...

And here's one more question:
When I use Session.Logon method, it returns Null. What does it mean? What
shoud I expect?

Signature

Regards
Tomski

Dmitry Streblechenko \(MVP\) - 28 Jul 2004 20:26 GMT
Hmmm... The type library does say that Logon returns variant, but I have
never seen the returned value documented or used anywhere.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

> > Dmitry Streblechenko (MVP) wrote:
> >> Do not call Session.Logon in CDO with the NewProfile parameter =
[quoted text clipped - 6 lines]
> When I use Session.Logon method, it returns Null. What does it mean? What
> shoud I expect?
Tomski - 29 Jul 2004 09:02 GMT
Dmitry Streblechenko (MVP) wrote:
> Hmmm... The type library does say that Logon returns variant, but I
> have never seen the returned value documented or used anywhere.

Nor did I. Btw it returns Null in my case.

Signature

Greetings
Tomski

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.