[fpc-pascal] Html mail displays differently than the body text does...

Bo Berglund bo.berglund at gmail.com
Thu Jan 18 18:46:28 CET 2018


I am using Indy 10 (latest trunk version) in Lazarus to create a
command line utility to interface with our new Subversion repository
server. It sends commit emails to select users with some information
including a list of changed files and with a URL line to allow the
recipient to access the file from the VisualSVN web interface.

This has worked fine until today when I tried a test case where the
file is named with the Swedish characters ÅÄÖåäö as part of the file
name. When I commit this file all seems to go fine and the file
appears as expected in the VSVN web interface with the correct name.

But in the received email the file name and URL is corrupted and
cannot be read or used. THe Swedish characters have been replaced by
question marks in black diamonds.

As part of the email sending the program logs stuff and it also
creates a file on disk with the mail body content (basically
message.body.savetofile(somename.html).

If I open this file in Chrome it displays properly with the correct
URL and name.
But in the received email I don't see this, neither in Outlook on the
PC nor in the Samsung Mail app on my phone.

Question:
---------
How should I format the html part of the email when loading it into
the TIdSMTP component for sending?

Currently I use a TStringList container as follows:

function CreateFileURL(Server, Repo, FilePath: string): string;
var
  sURL: string;
begin
  sURL := Server + '/!/#' + Repo + '/view/head/' + FilePath;
  Result := '<a href="' + sURL + '">' + ExtractFileName(FilePath) +
'</a>';
end;

In the caller:
slBody.Add('<html><head>' +
'<style type="text/css"><!--p,td { font-family: arial,helvetica;
font-size: 10pt }--></style>'+
'</head><body><table border=0>');
sLine := '<tr><td><b>SVN Server:</b></td><td>' + Computer +
'</td></tr>';
slBody.Add(sLine);
---- Lots of lines more ----
sTmp := SVNX.SvnData.FileList[i]; // <4 char OP><file path>
sTmp := CreateFileURL(SERVER_URL, REPONAME, CurDir + sTmp);
slBody.Add(sTmp + '</td></tr>');


The only thing I can think of now is to somehow tell the html part
that it is dealing with utf-8 data, but how? Should I put something
into the <head> part maybe?

I have already set the message to use UTF-8 via the messagebuilder:

IB := TIdMessageBuilderHtml.Create;
....
IB.HtmlCharSet := 'UTF-8';
IB.Html.Text := slBody.Text;
IB.PlainText.Text := slTxtBody.Text;
IB.FillMessage(SVNM.MailMessage);

Any ideas?

-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list