Einzelnen Beitrag anzeigen

Neumann

Registriert seit: 6. Feb 2006
Ort: Moers
529 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Dateianhang mit Indys

  Alt 24. Okt 2011, 11:17
Hallo,

habe die gleichen Probleme gehabt. Meine Lösung sieht etwa so aus:

Delphi-Quellcode:
procedure tdmm.sendmail(aSubject:string);
var
  Anhang:tidAttachmentfile;
  i:integer;
begin
  if mailactive and (fileexists(dml.savepath+'\'+asubject+'.xml')) then
  begin

    with IdMsgSend do
      begin
{$IFDEF SERVER}

         dmg.cdsclients.First;
         Recipients.Clear;
         i:=0;
         repeat
           Recipients.Add;
           Recipients[i].Address:=dmg.CdsClientsMail.AsString;

           inc(i);
           dmg.CdsClients.Next;
         until dmg.CdsClients.eof;
{$ELSE}
         Recipients.EMailAddresses := ReceiverEMail;
{$ENDIF}
         contenttype:='multipart/mixed' ;
         idMsgSend.IsEncoded:=true;
         From.Text := UserEmail;
         ReplyTo.EMailAddresses := UserEmail;
         ReceiptRecipient.Text := '';
         Subject := asubject; { Subject: header }

          Body.LoadFromFile(dml.savepath+'\'+asubject+'.xml'); // Nur für Testzwecke
         Priority := TIdMessagePriority(3); { Message Priority }

          Anhang:=TIdAttachmentFile.Create(IdMsgSend.MessageParts );
          Anhang.ContentType := 'text/plain';
          Anhang.StoredPathName:=dml.savepath+'\'+asubject+'.xml';
          Anhang.FileName:=extractfilename(asubject+'.xml');
          Anhang.OpenLoadStream;
          Anhang.CloseLoadStream;

      end;


     SMTP.Username := UserEmail;
     SMTP.Password := SmtpServerPassword;
     SMTP.Host := SmtpServerName;
     SMTP.Port :=SmtpServerPort;

   
     try
      try
        SMTP.Connect;
        SMTP.Send(IdMsgSend);
        deletefile(dml.savepath+'\'+asubject+'.xml');
        //messagedlg(_('Daten erfolgreich gesendet'),mtinformation,[mbok],0);
      except
      on e:exception do
        writeerrlog('Mail konnte nicht gesendet werden ',e);
      end;
     finally
        SMTP.Disconnect;
        Idmsgsend.MessageParts.Clear;
     end;
  end;
end;
Habe noch einige Properties im Objectinspector (IDMSG) gesetzt, die hier noch vieleicht wichtig sind:

AttachmentEncoding: MIME
ContentTransferEncoding: 8 bit
AttachmentTempdir:
Encoding: meMIME

Einiges davon kommt noch in die Procedure, ist noch nicht ganz fertig.
Ralf
Gruß vom Niederrhein
  Mit Zitat antworten Zitat