Recent

Author Topic: *SOLVED * £ sign not displaying properly in Synapse email  (Read 1426 times)

oldcoder

  • New Member
  • *
  • Posts: 13
*SOLVED * £ sign not displaying properly in Synapse email
« on: February 21, 2019, 01:53:39 pm »
Can someone help me please?
I want to send emails out that correctly display a £ sign in the text portion of the email but everything I have tried doesn't work properly.
I'm sure it'll be obvious from the following that I don't have much of a clue about character encoding, but I have assumed, rightly or wrongly, that the answer is to convert the text to UTF8 from whatever coding it may be in.

From posts I have read I have tried putting

{$modeswitch UnicodeStrings}
{$codepage utf-8}     

at the top of the unit

and the other various attempts are commented out in the code below.

The amount I have been trying to send is £6.35


procedure Tbillform.emaildocbtnClick(Sender: TObject);
var
  Result:Boolean;
  Mime:TMimemess;
  StrList : TStringList;
  p: TMimepart;
  s,t: string;
  i:integer;
begin
 if docemailtextlines.text <> '' then
 if emailtitle.text <> '' then
 begin
   try
   StrList := TStringList.Create;
   Mime := TMimeMess.Create;
   p := Mime.AddPartMultipart('mixed', nil);

{ for i := 0 to docemailtextlines.lines.count - 1 do
   begin
    if trim(docemailtextlines.lines) <> '' then
    StrList.Add(UTF8Encode(docemailtextlines.lines));
   end;}
   //above causes Ã_£6.35

   //Line below causes sigseg v
   //StrList.Add(UTF8Encode(docemailtextlines.text));

 {  for i := 0 to docemailtextlines.lines.count - 1 do
      begin
       if trim(docemailtextlines.lines) <> '' then
       StrList.Add(AnsiToUTF8(docemailtextlines.lines));
      end; }
   //above causes Ã_£6.35

{     for i := 0 to docemailtextlines.lines.count - 1 do
        begin
         if trim(docemailtextlines.lines) <> '' then
         StrList.Add(WinCPToUTF8(docemailtextlines.lines));
        end; }
// same


//     StrList.Add(ConvertEncoding(docemailtextlines.text, GuessEncoding(docemailtextlines.text),EncodingUTF8));
//     ^ didn't work either

   //Next line causes £6.35
   StrList.Add(docemailtextlines.text);

   StrList.Text := CP1252ToUTF8(StrList.Text);
   //above line causes Ã_£6.35



   Mime.Header.CharsetCode := synachar.UTF_8;
   Mime.Header.From := smtpsenderco+' <'+smtpusername+'>';
   Mime.Header.ReplyTo := smtpusername;
   Mime.Header.ToList.Add(email.text);
   Mime.Header.Subject := emailtitle.text;
   Mime.AddPartBinaryFromFile(docdir+'Cash Sale '+docnum.text+'.pdf',p);
   Mime.AddPartText(StrList,p);
   Mime.EncodeMessage;
   except
   on E: Exception do
   begin
    Showmessage ('Error creating email');
    Showmessage (E.Message);
   end;
  end;
« Last Edit: February 21, 2019, 05:14:13 pm by oldcoder »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: £ sign in Stringlist, taken from a memo, emailed via Synapse
« Reply #1 on: February 21, 2019, 02:38:17 pm »
I don't know if it's done automatically but check whether there is a content-type MIME header added to the message specifying the encoding, p.e.
  Content-type: text/plain; charset=utf-8
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

oldcoder

  • New Member
  • *
  • Posts: 13
Re: *SOLVED * £ sign not displaying properly in Synapse email
« Reply #2 on: February 21, 2019, 05:18:58 pm »
Thanks for your reply lucamar

If anyone is having a similar problem, I finally solved it by replacing the line:

Mime.AddPartText(StrList,p);

with

Mime.AddPartTextEx(StrList, p, UTF_8, True, ME_8BIT);   

which I found on the German Lazarus forum

 

TinyPortal © 2005-2018