Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2001, 01:08 PM
Wise Guy Wise Guy is offline
Member
 
Join Date: Jan 2001
Posts: 45
Default simple email question

what component is used in outlook xpress for message preview (one that can preview HMTL mails)? and how can i make it/find it?
Reply With Quote
  #2  
Old 01-27-2001, 05:47 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: simple email question

Win32Spy says it is class Internet_Explorer_Server, which
means you can get the same effect with TWebBrowser
component or the imported IE ActiveX component, if youy have
Reply With Quote
  #3  
Old 01-27-2001, 05:50 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: simple email question

I have some code at work that shows you how to load a
TWebBrowser component from a stream so that would help you
because you can read the HTML messages from storage into a
stream and then stream it directly int the TWebBrowser
component. It is required that IE be installed to use
TWebBrowser, however.

I will post it Monday.
Reply With Quote
  #4  
Old 01-27-2001, 01:11 PM
Wise Guy Wise Guy is offline
Member
 
Join Date: Jan 2001
Posts: 45
Default RE: RE: RE: simple email question

Hey. I've tried making it with a TWebBrowser component and it really whos me the content of a HTML email but not the way Outlook Xpress do it. The attachment is really a web page and can be decoded to a browser, but neither IE, nor TWebBrowser decode it as it is done in the Outlook Express... That's why I asked this question.

Thanks for answering... but it won't do the job
Reply With Quote
  #5  
Old 01-29-2001, 11:18 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: simple email question {Long explaination}

Ok, let me explain how it is done in OE.
{Note: This comment contains HTML code so I replaced
the < and > with [ and ] due to the site not being
able to handle many HTML tags}


The html mail is appended to the standard SMTP message as a
multi-part message with the Content-Type of text/html. Save
one of your HTML messages to disk and open it in Notepad.

You will see something lookinglike this:
------=_NextPart_001_005C_01C089FA.90815C00
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

[!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"]
HTML Code:
  [HEAD]
    [META content="text/html; charset=iso-8859-1"
          http-equiv=Content-Type]
    [META content="MSHTML 5.00.2919.6307" name=GENERATOR]
    [STYLE][/STYLE]
  [/HEAD]
  [BODY bgColor=#ffffff]
    [html code snipped]
  [/BODY]
------=_NextPart_001_005C_01C089FA.90815C00--


Next, if there are any embedded images, you will see something
like this in your HTML:

[IMG align=baseline alt="" border=0 hspace=0
src="cid:005a01c08a2c$db1bcc00$0b01a8c0@moby2"]

and then another part like this:
{see how the Content-ID and IMG tag cid element match

------=_NextPart_000_005B_01C089FA.90815C00
Content-Type: image/gif;
name="Cloud.gif"
Content-Transfer-Encoding: base64
Content-ID: [005a01c08a2c$db1bcc00$0b01a8c0@moby2]

R0lGODlhZAI8APf/AP//////zP//mf//Zv//M///AP/M///MzP/
[base64 code snipped]
lOUPhDthTGt1EaOdGZP10wsIADs=

------=_NextPart_000_005B_01C089FA.90815C00--

Now, to show this in the TWebBrowser, you first need to
determine if the mail is a multipart mail and then see if
one of the parts is HTML. Depending upon which POP3
component you are using, you should be able to get the
multipart info from it. Then. load the message into a
stringlist and parse out the HTML and show it in your
TWebBrowser. And, if there are embedded images, you can
show them too by decoding the base64 strings and saving the
image to a file and use a local URL to the file.

I am at home today and won't be able to get to the source showing you how to write a stream to the TWebBrowser. If
you are going to tackle this, you will first need to be
able to parse the message.

So you see, there's a way around everything.
Good luck...
Reply With Quote
  #6  
Old 01-30-2001, 06:40 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: simple email question {Long explaination}

Here is the MemoryStreamToWebBrowser example I promised:

// This writes a MemoryStream to the WebBrowser document
// without using any disk access
procedure TForm1.Button1Click(Sender: TObject);
var
M:TMemoryStream;
doc:variant;
S:string;
begin
WebBrowser1.navigate('about:blank');
M:=TMemoryStream.Create;
try
// I used a Memo to add data to the Stream.
Memo1.Lines.SaveToStream(M);
M.position:=0;
SetLength(S, M.Size);
M.Read(S[1],M.Size);
doc:=WebBrowser1.Document;
doc.Write(S);
finally
M.Free;
end;
end;

Now, you need a base64 conversion routine, too. Here is one
that I culled from Andreas Horstmeier's TCP/IP component
suite.

unit _Base64;

{
Unit source cut from Andreas Horstmeier's TCP/IP component suite.
}

interface
uses
sysutils,
windows,
classes;
type
ta_8u=packed array [0..65530] of byte;
t_encoding=(uuencode,base64,mime);

function encode_base64(data: TStream):TStringList;
function decode_base64(source:TStringList):TMemoryStream;
function encode_line(mode:t_encoding; const buf; size:Integer):String;
function decode_line(mode:t_encoding; const inp:String):String;
function poscn(c:char; const s:String; n: Integer):Integer;

const
bin2b64:String='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh ijklmnopqrstuvwxyz0123456789+/';
b642bin:String='~~~~~~~~~~~^~~~_TUVWXYZ[\]~~~|~~~ !"#$%&''()*+,-./0123456789~~~~~~:;<=>?@ABCDEFGHIJKLMNOPQRS';
bin2uue:String='`!"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_';
uue2bin:String=' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ ';
linesize = 45;

implementation

function poscn(c:char; const s:String; n: Integer):Integer;
var
i: Integer;
begin
if n=0 then n:=1;
if n>0 then
begin
for i:=1 to length(s) do
begin
if s[i]<>c then
begin
dec(n);
Result:=i;
if n=0 then
begin
EXIT;
end;
end;
end;
end
else
begin
for i:=length(s) downto 1 do
begin
if s[i]<>c then
begin
inc(n);
Result:=i;
if n=0 then
begin
EXIT;
end;
end;
end;
end;
poscn:=0;
end;

function decode_line(mode:t_encoding; const inp:String):String;
var
count,pos1,pos2: Integer;
offset: shortint;
s: String;
sOut: String;
begin
s:=inp;
setlength(sOut,length(s)*3 div 4 +3);
fillchar(sOut[1],length(s)*3 div 4 +3,#0);
if (mode=uuencode) and not (s[1] in [' '..'M','`']) then
count:=0
else
begin
count:=0;
pos1:=0;
case mode of
uuencode:
begin
count:=(ord(s[1]) - $20) and $3f;
for pos1:=2 to length(s)-1 do
s[pos1]:=char(ord(uue2bin[ord(s[pos1])-$20+1])-$20);
pos1:=2;
end;// uuencode
base64,mime:
begin
count:=poscn('=',s,-1)*3 div 4;
for pos1:=1 to length(s) do
s[pos1]:=char(ord(b642bin[ord(s[pos1])-$20+1])-$20);
pos1:=1;
end;// base64, mime
end;// case
pos2:=1;
offset:=2;
while pos2<=count do
begin
if (pos1>length(s)) or ((mode<>uuencode) and (s[pos1]='\')) then
begin
if offset<>2 then
inc(pos2);
count:=pos2-1;
end
else
if ((mode<>uuencode) and (s[pos1]='^')) then
inc(pos1)
else
if offset>0 then
begin
sOut[pos2]:=char(ord(sOut[pos2]) or (ord(s[pos1]) shl offset));
inc(pos1);
offset:=offset-6;
end
else
if offset<0 then
begin
offset:=abs(offset);
sOut[pos2]:=char(ord(sOut[pos2]) or (ord(s[pos1]) shr offset));
inc(pos2);
offset:=8-offset;
end
else
begin
sOut[pos2]:=char(ord(sOut[pos2]) or ord(s[pos1]));
inc(pos1);
inc(pos2);
offset:=2;
end;// if ((mode<>uuencode) and (s[pos1]='^'))
end;// while pos2<=count
end;// if (mode=uuencode) and not (s[1] in [' '..'M','`'])
decode_line:=copy(sOut,1,count);
end;// function decode_line

function encode_line(mode:t_encoding; const buf; size:Integer):String;
var
buff: ta_8u absolute buf;
offset: shortint;
pos1,pos2: byte;
i: byte;
sOut: String;
begin
setlength(sOut,size*4 div 3 + 4);
fillchar(sOut[1],size*4 div 3 +2,#0);
if mode=uuencode then
begin
sOut[1]:=char(((size-1) and $3f)+$21);
size:=((size+2) div 3)*3;
end;// if
offset:=2;
pos1:=0;
pos2:=0;
case mode of
uuencode: pos2:=2;
base64, mime: pos2:=1;
end;// case
sOut[pos2]:=#0;
while pos1 begin
if offset > 0 then
begin
sOut[pos2]:=char(ord(sOut[pos2]) or ((buff[pos1] and ($3f shl offset)) shr offset));
offset:=offset-6;
inc(pos2);
sOut[pos2]:=#0;
end
else
if offset < 0 then
begin
offset:=abs(offset);
sOut[pos2]:=char(ord(sOut[pos2]) or ((buff[pos1] and ($3f shr offset)) shl offset));
offset:=8-offset;
inc(pos1);
end
else
begin
sOut[pos2]:=char(ord(sOut[pos2]) or ((buff[pos1] and $3f)));
inc(pos2);
inc(pos1);
sOut[pos2]:=#0;
offset:=2;
end;
end;

case mode of
uuencode:
begin
if offset=2 then dec(pos2);
for i:=2 to pos2 do
sOut[i]:=bin2uue[ord(sOut[i])+1];
end;// uuencode
base64, mime:
begin
if offset=2 then dec(pos2);
for i:=1 to pos2 do
sOut[i]:=bin2b64[ord(sOut[i])+1];
while (pos2 and 3)<>0 do
begin
inc(pos2);
sOut[pos2]:='=';
end;
end;// base64, mime
end;// case
encode_line:=copy(sOut,1,pos2);
end;// function encode_line

function encode_base64(data: TStream):TStringList;
var
buf: pointer;
size: Integer;
begin
buf:=NIL;
try
Result:=TStringList.Create;
getmem(buf,linesize);
data.seek(0,0);
size:=linesize;
while size>0 do
begin
size:=data.read(buf^,linesize);
if size>0 then
Result.add(encode_line(base64,buf^,size));
end;// while
finally
if buf<>NIL then
freemem(buf,linesize);
end;// try
end;// function encode_base64

function decode_base64(source:TStringList):TMemoryStream;
var
i: Integer;
s: String;
begin
Result:=TMemoryStream.Create;
for i:=0 to source.count-1 do
begin
s:=decode_line(base64,source[i]);
Result.write(s[1],length(s));
end;// for
end;// function decode_base64

end.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:53 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.