This function solved my problem since I was exporting from a Richedit...
function TFEnviarMailDirecto.RtfToHtml(RICH: TcxRichEdit): string;
var
I,J,max_array: integer;
html: string;
F,FO: array [0..5] of string;
str,lgt: integer;
size,breaklines: integer;
cor : string;
begin
html := '';
str := rich.SelStart;
lgt := rich.SelLength;
MAX_ARRAY := 5;
breaklines:=0;
for J := 0 to MAX_ARRAY do
begin
F[J] := '';
FO[J] := '';
end;
for I := 0 to length(RICH.text) do
begin
RICH.SelStart := I-BREAKLINES;
RICH.SelLength := 1;
for J := 0 to MAX_ARRAY do
FO[J] := F[J];
if (RICH.SelAttributes.Style - [fsItalic] - [fsUnderline] - [fsStrikeOut] = [fsBold]) then
F[0] := '<b>'
else
F[0] := '</b>';
if (RICH.SelAttributes.Style - [fsItalic] - [fsBold] - [fsStrikeOut] = [fsUnderline]) then
F[1] := '<u>'
else
F[1] := '</u>';
if (RICH.SelAttributes.Style - [fsUnderline] - [fsBold] - [fsStrikeOut] = [fsItalic]) then
F[2] := '<i>'
else
F[2] := '</i>';
if RICH.SelAttributes.size < 10 then
SIZE := 1
else if RICH.SelAttributes.size < 12 then
SIZE := 2
else if RICH.SelAttributes.size < 14 then
SIZE := 3
else if RICH.SelAttributes.size < 18 then
SIZE := 4
else if RICH.SelAttributes.size < 22 then
SIZE := 5
else if RICH.SelAttributes.size < 32 then
SIZE := 6
else
SIZE := 7;
COR := ColorToString(RICH.SelAttributes.Color);
if (COR = 'clWindowText') or (COR = 'clBlack') then
COR := '#000000'
else if COR = 'clWite' then
COR := '#FFFFFF'
else if COR = 'clAqua' then
COR := '#00FFFF'
else if COR = 'clFuchsia' then
COR := '#FF00FF'
else if COR = 'clBlue' then
COR := '#0000FF'
else if COR = 'clYellow' then
COR := '#FFFF00'
else if COR = 'clLime' then
COR := '#00FF00'
else if COR = 'clRed' then
COR := '#FF0000'
else if COR = 'clSilver' then
COR := '#C0C0C0'
else if COR = 'clGray' then
COR := '#808080'
else if COR = 'clTeal' then
COR := '#008080'
else if COR = 'clPurple' then
COR := '#800080'
else if COR = 'clNavy' then
COR := '#000080'
else if COR = 'clOlive' then
COR := '#808000'
else if COR = 'clGreen' then
COR := '#008000'
else if COR = 'clMaroon' then
COR := '#800000'
else if copy(COR,1,1) = '$' then
COR := '#'+copy(COR,length(COR)-1,2)
+copy(COR,length(COR)-3,2)
+copy(COR,length(COR)-5,2)
else
COR := '#000000';
F[3] := '</font><font face="'+RICH.SelAttributes.Name+'" size='+inttostr(SIZE)+' color="'+COR+'">';
if RICH.Paragraph.Alignment = taCenter then
F[4] := '<center>'
else
F[4] := '</center>';
if RICH.Paragraph.Alignment = taRightJustify then
F[5] := '<div align="right">'
else
F[5] := '</div>';
for J := 0 to MAX_ARRAY do
if FO[J] <> F[J] then
HTML := HTML + F[J];
if copy(RICH.text,I+1,1) = #13 then
begin
inc(BREAKLINES);
HTML := HTML + '<br>';
end;
HTML := HTML + copy(RICH.text,I+1,1);
end;
RICH.SelStart := STR;
RICH.SelLength := LGT;
result := HTML;
end;
From what I’ve researched, the way is to send as
HTML
. Ever tried it? You’d have to convert theRTF
forHTML
and then send, theContentType
should be amended to text/html.– Andrey
This means formatting text between tags?
– Bruno Ribeiro
Friend, see the following links: Soen. This link I did not test, but by his acceptance in Soen, seems to be interesting. Link refers to my first comment, see how it is first saved in
Word
, to convert toHTML
and then sent by email. It’s kind of funny, but it might work. ,RTF
only in theMicrosoft Outlook
(or similar), the rest has to beHTML
.– Andrey
Thank you very much! The first option had already tested but it has the same behavior. I will now try to make the conversion to html and see how it behaves. As soon as I find some solution I put here. this is found....
– Bruno Ribeiro