Einzelnen Beitrag anzeigen

Drumbo

Registriert seit: 18. Okt 2013
22 Beiträge
 
#1

[Indy] Attachement (related und nicht-related) + html + text funktioniert nicht

  Alt 10. Jan 2018, 14:32
Guten Tag,

ich suche schon seit mehreren Stunden nach einer Lösung für mein Indy-Email Problem.
Und zwar möchte ich zum einen eine Email schicken, welche eine PDF im Anhang hat, welcher auch als solcher angezeigt werden soll!.
Des Weiteren möchte ich aber auch eine Html-Signatur verschicken, in der ein Logo drin ist, welches wiederum nicht in den Anhängen auftauchen soll und zu guter letzt möchte ich auch noch 1-2 Sätze "normalen Text" hinzufügen.
Bis auf den normalen Text funktioniert auch alles problemlos.
Auf diesen kann ich allerdings nicht verzichten.
Untenstehend findet ihr den Code.
Die Geschichte mit den MessageParts hab ich von der Indy Seite (http://www.indyproject.org/Sockets/B...8_17_A.EN.aspx).
Wenn ich alle Parentparts wie auf der Seite beschrieben nutze, bleibt mein Programm hängen.

Delphi-Quellcode:
procedure TfrmMessageEditor.CreateAndSendEmail(MailTo:String;ExtSubject:String;AttachmentPath:string;BodyText:tstrings;contenttype:string);
var
  lTextPart: TIdText;
  TechnikSignatur:string;
begin

IdMsgSend:=TIdMessage.Create(nil); // Erstellen der Message
// Html Datei für individuelle HTML-Signaturen für diverse Techniker
TechnikSignatur:='<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
TechnikSignatur:=TechnikSignatur+'</head><body><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="padding-left: 0px; padding-top: 0px; padding-bottom: 0px; padding-right: 0px;">';
TechnikSignatur:=TechnikSignatur+'<span style="text-align: left; color: #000000; font-family: ''Arial'', sans-serif; font-size: 10pt; font-weight: bold"> ';
TechnikSignatur:=TechnikSignatur+trim(Main.Techniker_Anmelde_datasetVorname.Value)+' '+trim(Main.Techniker_Anmelde_datasetName.Value)+'</span><br><span style="text-align: left; margin-top: 0px; margin-bottom: 0px; color: #000000; font-family: ''Arial'', sans-serif;' ;
TechnikSignatur:=TechnikSignatur+'font-weight: normal; font-size: 9pt;"> '+trim(Main.Techniker_Anmelde_datasetTitel.value)+'</span><br></td></tr>';
//PDF Anhang generieren falls notwendig
    if AttachmentPath<>'then
        begin
          with TIdAttachmentFile.Create(IdMsgSend.MessageParts, AttachmentPath) do
          begin
            FileName:= ExtSubject+'.pdf';
          end;
        end;

//IDMessage konfigurieren
     with IdMsgSend do
      begin
         Body.Clear;
         From.Text := Main.Techniker_Anmelde_datasetemail.Value;
         ReplyTo.EMailAddresses := Main.Techniker_Anmelde_datasetemail.Value;
         Recipients.EMailAddresses := MailTo; { To: header }
         Subject := ExtSubject; { Subject: header }
         Priority := TIdMessagePriority(cboPriority.ItemIndex); { Message Priority }
         CCList.EMailAddresses := edtCC.Text; {CC}
         BccList.EMailAddresses := edtBCC.Text; {BBC}
         ReceiptRecipient.Text := Main.Techniker_Anmelde_datasetemail.Value;
      end;
// Verschiedene MessageParts erstellen (wie auf http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.EN.aspx beschrieben)
     with TIdText.Create(IdMsgSend.MessageParts, nil) do begin
      ContentType := 'multipart/related; type="multipart/alternative"';
    end;
    with TIdText.Create(IdMsgSend.MessageParts, nil) do begin
      ContentType := 'multipart/alternative';
    end;
    with TIdText.Create(IdMsgSend.MessageParts, nil) do begin
      Body.text:='TestTestTest';
      ContentType := 'text/plain';
    end;
    with TIdText.Create(IdMsgSend.MessageParts, nil) do begin
      Body.Text := TechnikSignatur+Options_form.Option_datasetMailSignature.Value;
      ContentType := 'text/html';
    end;

  if not FileExists(ExtractFilePath(ParamStr(0))+'Logo.gif') then
    Options_form.DBAdvPicture1.Picture.SaveToFile(ExtractFilePath(ParamStr(0))+'Logo.gif');
  With TIdAttachmentFile.Create(IdMsgSend.MessageParts,ExtractFilePath(ParamStr(0))+'Logo.gif' ) do begin
      ContentID := 'image1';
      ContentType := 'image/gif';
      FileName := 'Logo.gif';
    end;
   IdMsgSend.ContentType := 'multipart/mixed';
  {authentication settings}
   SMTP.AuthType := satdefault; {Simple Login}

   SMTP.Username := Main.Techniker_Anmelde_datasetemail.Value;
   SMTP.Password := Main.Techniker_Anmelde_datasetMailPasswort.Value;

   {General setup}
   SMTP.Host := main.Techniker_Anmelde_datasetsmtphost.Value;
   SMTP.Port := main.Techniker_Anmelde_datasetsmtpport.value;

   {now we send the message}
   SMTP.Connect;
   try
      SMTP.Send(IdMsgSend);
   finally
      SMTP.Disconnect;
   end;
   IdMsgSend.free;
end;
Ich hoffe ihr könnt mir helfen.

Gruß Chris
  Mit Zitat antworten Zitat