AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi Indy 10 und HTML Emails Probleme
Thema durchsuchen
Ansicht
Themen-Optionen

Indy 10 und HTML Emails Probleme

Ein Thema von Jelly · begonnen am 23. Sep 2005
Antwort Antwort
Benutzerbild von Jelly
Jelly

Registriert seit: 11. Apr 2003
Ort: Moestroff (Luxemburg)
3.741 Beiträge
 
Delphi 2007 Professional
 
#1

Indy 10 und HTML Emails Probleme

  Alt 23. Sep 2005, 15:01
Ich nutze schon seit einiger Zeit sehr erfolgreich folgende Teilroutinen, um über die Indy Komponenten EMails im HTML und PlainText Format zu versenden. Im HTML können sogar direkt Grafiken eingebettet, genau wie ich es wollte... Das Ganze unter Indy 6(glaub ich, oder wars 8), in Delphi 4.

Jetzt habe ich aber in meinem Delphi die Indy 10 kompos installiert, und da kommt in meinem Mailclient nur noch Mist heraus:

Ich erstelle mehrere Messageparts, darunter die HTML Mail, die TextMail, eventuelle Bilder im HTML und die normalen Attachments.

Der HTML Teil wird in der Routine HTML_Part abgewickelt.

So, meine Frage sollte eigentlich schon klar sein. Wieso kommt unter Indy10 Mist heraus?

Delphi-Quellcode:
function TMailTemplate.Send : boolean;
var
 i : integer ;
begin
      if assigned (OnSendBegin) then OnSendBegin (Self) ;
      application.processmessages ;

     IndySMTP.OnWork := Work ;
     IndySMTP.OnWorkBegin := WorkBegin ;

     { Text Part }
     if FUseHTML then with TIdText.Create(IndyMessage.MessageParts) do begin
        ContentType := 'text';
        Body.Text := BodyPlain ;
     end else begin
        IndyMessage.ContentType := 'text/plain' ;
        IndyMessage.Body.Text := BodyPlain ;
     end ;

     { Subject }
     IndyMessage.Subject := Subject ;

     { HTML Part }
     if FUseHTML then HTML_Part ;

     { Attachments }
     for i := 0 to Attachments.Count-1 do
       TIdAttachmentFile.Create(IndyMessage.MessageParts, Attachments[i]);

     with IndySMTP do begin
        try
           Connect ;
           Send (IndyMessage) ;
           Disconnect ;
           Result := true ;
        except
            Result := false ;
        end ;
     end ;

     if assigned (ProgressBar) then ProgressBar.Position := ProgressBar.Max ;
     if assigned (OnSendEnd) then OnSendEnd (Self) ;
     application.processmessages ;
end;

function TMailTemplate.HTML_Part : byte;
var
    i,x,y : integer;
    img : string;
    ContentID : integer;
    sContentID: string ;
    HTMLText : string ;
    imgabs : string ;
begin
  result:=0;
  HTMLText := Body.text ;
  try

    //Alle img-Tags verarbeiten
    ContentID:=10001;
    sContentID := IntToStr(ContentID) ;

    y:= pos('<IMG',UpperCase(HTMLText));
    while y>0 do
    begin
      i:= PosEx('SRC="',UpperCase(HTMLText),y);
      if i>0 then
      begin
        x:=PosEx('"',HTMLText,i+6);
        img:=copy(HTMLText,i+5,x-i-5);
        imgabs := Header.EmbeddedImagePath + ExtractFilename(img) ;
        delete(HTMLText,i+5,x-i-5);
        insert('cid:'+IntToStr(ContentID)+'@'+imgabs,HTMLText,i+5);
        //IMG als Attachment anfügen
        with TIdAttachmentFile.Create(IndyMessage.MessageParts, imgabs) do
        begin
          // hier wird diese CONTENT-ID definiert!
          ExtraHeaders.Values['Content-ID'] := sContentID +'@'+imgabs;
        end;
        inc(ContentID);
      end;
      y:=PosEx('<IMG',UpperCase(HTMLText),y+1);
    end;

    //HTML-Message erzeugen
    with TIdText.Create(IndyMessage.MessageParts) do
    begin
      ContentType := 'text/html';
      Body.Add(HTMLText);
    end;

  finally
  end;
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:46 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