Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Indy SMTP Email wie Body encoding setzen (https://www.delphipraxis.net/195331-indy-smtp-email-wie-body-encoding-setzen.html)

Kostas 20. Feb 2018 14:45

Indy SMTP Email wie Body encoding setzen
 
Hallo Zusammen,


Hat jemand eine Idee wie das encoding beim body gesetzt werden kann.

Das sollte gesetzt werden.
Code:
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Wenn das nicht gesetzt wird, können manche Email-Clients die Umlaute nicht richtig darstellen.


Delphi-Quellcode:
procedure TForm3.Button1Click(Sender: TObject);
var Attachment : TIdAttachment;
begin
  idSMTP.Host := 'mail.server.de';
  idSMTP.Username := 'user';
  idSMTP.Password := 'pwd';
  idSMTP.Port := 25;
  idSMTP.Connect;

  idMessage.Clear;
  idMessage.From.text := 'kostas@server.de';
  idMessage.Sender.text := idMessage.From.text;
  idMessage.Recipients.EMailAddresses := 'empfaenger@server.de';
  idMessage.CCList.EMailAddresses := '';
  idMessage.BccList.EMailAddresses := '';
  idMessage.Subject := 'Umlaute öäüß ÖÄÜ';
  idMessage.Body.Add('Umlaute öäüß ÖÄÜ');

  idSMTP.Authenticate;
  idSMTP.Send( idMessage );


  idSMTP.Disconnect;


end;
Gruß Kostas

Gollum 20. Feb 2018 15:26

AW: Indy SMTP Email wie Body encoding setzen
 
Hallo Kostas,

das müsste so gehen:

Delphi-Quellcode:
...
  idMessage.Clear;

  idMessage.ContentType:='text/plain; charset=utf-8';
  idMessage.ContentTransferEncoding:='quoted-printable'

  idMessage.From.text := 'kostas@server.de';
...

Kostas 20. Feb 2018 16:52

AW: Indy SMTP Email wie Body encoding setzen
 
Hallo Gollum,

Danke für den Hinweis. Ich habe die zwei String nun so abgeändert weil es Thunderbird auch so macht.
Die Umlaute funktionieren jetzt allerdings NUR wenn keine Anhänge mit gesendet werden.

Code:
idMessage.ContentType:='text/plain; charset=utf-8; format=flowed';
  idMessage.ContentTransferEncoding:='8bit';

Das ist der Body ohne Anhang
Umlaute öäüß ÖÄÜ


Sobald Anhänge mit gesendet werden, die Email beschädigt. Das Bild wird nicht angezeigt und der Inhalt des Bodys sieht so aus:

Code:
This is a multi-part message in MIME format

--I=_Kg9TP5ZudylFbGNshsfz3ufDBVvUCeM
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Umlaute =C3=B6=C3=A4=C3=BC=C3=9F =C3=96=C3=84=C3=9C

--I=_Kg9TP5ZudylFbGNshsfz3ufDBVvUCeM
Content-Type: image/pjpeg;
    name="A02-6176_1.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
    filename="A02-6176_1.jpg"

/9j/4AAQSkZJRgABAQEA5gDmAAD/4RUmRXhpZgAASUkqAIACAABQRU5UQUNPTiBESUdJVEFMIENB
TUVSQQDmAAAAAQAAAOYAAAABAAAAVmVyc2lvbiAxLjA5MDAAAFBFTlRBQ09OAABMTSA4NTAzAIUA
...........
Gruß Kostas

Mathias Gerlach 20. Feb 2018 18:51

AW: Indy SMTP Email wie Body encoding setzen
 
Hallo Kostan,

habe momentan meinen Sourcecode nicht zur Hand, aber ich glaube, sobald Du Anhänge dabei hast, musst Du den ContentType ändern:

Code:
idMessage.ContentType := 'multipart/mixed';
Gruß
Mathias

Kostas 20. Feb 2018 20:36

AW: Indy SMTP Email wie Body encoding setzen
 
Hallo Matthias,

perfekt. Jetzt funktioniert alles mit und ohne Anhang.


Delphi-Quellcode:
procedure TForm3.Button1Click(Sender: TObject);
const aFile='F:\A02-6176_1.jpg';
var Attachment : TIdAttachment;
    sBody:string;
    lTextPart: TIdText;
    WithImage:Boolean;
begin
  idSMTP.Host := 'mail.server.de';
  idSMTP.Username := 'user';
  idSMTP.Password := 'pwd';
  idSMTP.Port := 25;
  idSMTP.Connect;

  idMessage.Clear;

  WithImage := True;

  idMessage.From.text := 'kostas@server.de';
  idMessage.Sender.text := idMessage.From.text;
  idMessage.Recipients.EMailAddresses := 'kostas@server.de';
  idMessage.CCList.EMailAddresses := '';
  idMessage.BccList.EMailAddresses := '';
  idMessage.Subject := 'Umlaute öäüß ÖÄÜ';


  if WithImage then
  begin
    idMessage.ContentType:='multipart/mixed';
    idMessage.ContentTransferEncoding:='8bit';

    idMessage.Body.Clear;

    lTextPart := TIdText.Create(idMessage.MessageParts);
    lTextPart.Body.Text := 'Umlaute öäüß ÖÄÜ';
    lTextPart.ContentType := 'text/plain; charset=utf-8; format=flowed';
    lTextPart.ContentTransfer := '8bit';

    with TIdAttachmentFile.Create( idMessage.MessageParts, aFile ) do
    begin
      idMessage.MessageParts.Add;
    end;
  end else
  begin

    idMessage.ContentType:='text/plain; charset=utf-8; format=flowed';
    idMessage.ContentTransferEncoding:='8bit';

    idMessage.Body.Add('Umlaute öäüß ÖÄÜ');

  end;


  idSMTP.Authenticate;
  idSMTP.Send( idMessage );


  idSMTP.Disconnect;


end;

Herzlichen Dank an alle. :-)
Gruß Kostas

stalkingwolf 19. Mär 2018 10:15

AW: Indy SMTP Email wie Body encoding setzen
 
Funktioniert das mit JPEG und Multipart in Thunderbird?
Weil wir hatten da vor kurzem massive Probleme.
Indy hat dort immer application/octet-stream als ContentTyp reingeschrieben und Thunderbird uns daher das Bild zerschossen.
D.h in der neusten Version hat Thunderbird beim speichern das Bild zerstört. Zwar gleiche Anzahl von Byte, aber falsch aufgebaut.

Daher habe ich die IDMessageClient Unit angepasst und kümmere mich in SendBody selber darum.

Kostas 19. Mär 2018 13:37

AW: Indy SMTP Email wie Body encoding setzen
 
Ja, bei mir funktioniert der Emailversand jetzt einwandfrei.

Ich habe es mit JPEG, PNG und PDF einzel und in Kombination ausprobiert. Alles einwandfrei in Thunderbird angekommen.

Gruß Kostas


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz