AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi [INDY] TIdSMTP und Anhänge
Thema durchsuchen
Ansicht
Themen-Optionen

[INDY] TIdSMTP und Anhänge

Ein Thema von ByTheTime · begonnen am 21. Dez 2013 · letzter Beitrag vom 3. Nov 2020
Antwort Antwort
ByTheTime

Registriert seit: 24. Sep 2011
Ort: Frankfurt
297 Beiträge
 
Delphi XE2 Architect
 
#1

AW: [INDY] TIdSMTP und Anhänge

  Alt 22. Dez 2013, 13:43
Okay, nochmal etwas genauer
Hier ist eine Lösung dazu, die aber bei mir nicht funkt

Delphi-Quellcode:
with IdMessage do
  begin
    ContentType := 'multipart/*'; // Wichtig für Anhang!

    From.Address := ASender;
    for i := 0 to ARecipients.Count - 1 do
      Recipients.Add.Address := ARecipients.Strings[i];

    for i := 0 to AAttachment.Count - 1 do // Wichtig für Anhang!
      TIdAttachmentFile.Create(IdMessage.MessageParts, // Wichtig für Anhang!
         AAttachment.Strings[i]); // Wichtig für Anhang!
    IdMessage.MessageParts.Add(); // Wichtig für Anhang!

    Subject := ASubject;
    Body := ABody;
  end;
Die mit " // Wichtig für Anhang!" markierten Zeilen habe ich aus dem verlinkten Thread entnommen, allerdings geht das schief :/

Ich hoffe es findet sich eine Lösung
Lukas
  Mit Zitat antworten Zitat
ByTheTime

Registriert seit: 24. Sep 2011
Ort: Frankfurt
297 Beiträge
 
Delphi XE2 Architect
 
#2

AW: [INDY] TIdSMTP und Anhänge

  Alt 24. Dez 2013, 10:39
Okay, nach viel hin und her und unzähligen Fehlversuchen, kann ich nun einen Anhang schicken Hier die Lösung

Delphi-Quellcode:
    with IdMessage do
      begin
        ContentType := 'multipart/' + ExtractFileExt(FileToSend);

        From.Address := ASenderAdress;
        From.Name := ASenderName;
        Subject := ASubject;

        Recipients.EMailAddresses := ARecipients;

        IdText := TIdText.Create(MessageParts, nil);
        IdText.ContentType := 'text/plain';
        IdText.Body.Text := ABody;
      end;

      if FileToSend <> 'then
      begin
        Attachment := nil;

        Attachment := TIdAttachmentFile.Create(IdMessage.MessageParts,
          FileToSend);
        Attachment.FileName := ExtractFileName(FileToSend);
        Attachment.ContentType := 'application/' + ExtractFileExt(FileToSend);
      end;
Irgendwann finde ich auch schon noch raus, wie es mit mehreren geht

P.S: Mit hilfe hiervon!
Lukas
  Mit Zitat antworten Zitat
ByTheTime

Registriert seit: 24. Sep 2011
Ort: Frankfurt
297 Beiträge
 
Delphi XE2 Architect
 
#3

AW: [INDY] TIdSMTP und Anhänge

  Alt 24. Dez 2013, 11:39
Okay, nach viel gesuche, ging es nun doch relativ schnell

Delphi-Quellcode:
    with IdMessage do
      begin
        ContentType := 'multipart/*';

        From.Address := ASenderAdress;
        From.Name := ASenderName;

        Subject := ASubject;

        Recipients.EMailAddresses := ARecipients;

        IdText := TIdText.Create(MessageParts, TStringList.Create);
        IdText.ContentType := 'text/plain';
        IdText.Body.Text := ABody;
      end;

      if Trim(Files) <> EmptyStr then
      begin
        try
          IdAttachmentList := TStringList.Create;
          IdAttachmentList.CommaText := Files;

          for i := 0 to IdAttachmentList.Count - 1 do
          begin
            IdMessage.IsEncoded := True;

            IdAttachment := TIdAttachmentFile.Create(IdMessage.MessageParts,
              IdAttachmentList.Strings[i]);
            IdAttachment.FileName :=
              ExtractFileName(IdAttachmentList.Strings[i]);
            IdAttachment.ContentType := 'application/octet-stream';
            IdAttachment.OpenLoadStream;
            IdAttachment.CloseLoadStream;
          end;
        finally
          IdAttachmentList.Free;
        end;
      end;
Hierund hier gab es noch was schönes

Für Verbesserungen, Optimierungen und Vorschläge bin ich gerne offen

Gruß,
Lukas
Lukas

Geändert von ByTheTime (24. Dez 2013 um 11:40 Uhr) Grund: Code formatiert ;)
  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 13:11 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz