AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke eMails per idPOP3 abholen und als html speichern..
Thema durchsuchen
Ansicht
Themen-Optionen

eMails per idPOP3 abholen und als html speichern..

Ein Thema von erich.wanker · begonnen am 28. Jun 2012 · letzter Beitrag vom 28. Jun 2012
 
Benutzerbild von erich.wanker
erich.wanker

Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
464 Beiträge
 
Delphi XE4 Professional
 
#1

eMails per idPOP3 abholen und als html speichern..

  Alt 28. Jun 2012, 10:53
Hallo Leute,

würde gerne meine Mails via TidPOP3 abholen und als html oder txt Datei speichern, falls die Mail Anhänge besitzt, sollen die auch abgespeichert werden.

Hab jetzt folgende Zeilen, aber ist das auch stabil ?

Mein Test:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdContext, IdBaseComponent, IdComponent, IdCustomTCPServer,
  IdTCPServer, IdCmdTCPServer, IdExplicitTLSClientServerBase, IdPOP3Server,
  Buttons, IdTCPConnection, IdTCPClient, IdMessageClient, IdPOP3, ComCtrls,
  IdMessage, StdCtrls, IdMessageCoder, IdMessageCoderMIME,IdText ,IdAttachment,
  IdIOHandler, IdIOHandlerStream, IdIOHandlerSocket, IdIOHandlerStack;

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    POP: TIdPOP3;
    msg: TIdMessage;
    Memo1: TMemo;
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
var MailCount,Mailgroesse,intIndex :Integer;
    itm:TListItem;
    i:integer;
    s:string;
begin

      POP.Host := 'pop.1und1.de';
      POP.Port := 110;
      POP.Username := '++++';
      POP.Password := '+++++';
      POP.Connect;

      MailCount := POP.CheckMessages;

      if MailCount >0 then
      begin

          for intIndex := 1 to MailCount do
          begin
            msg.Clear;
            pop.Retrieve(intIndex, Msg);
            
            memo1.Lines.Append('**************************');
            memo1.Lines.Append('Von: '+Msg.From.Text);
            memo1.Lines.Append('Antwortadresse: '+msg.from.Address );
            memo1.Lines.Append('Betreff: '+Msg.Subject);
            memo1.Lines.Append('Priorität: '+inttostr(ord(Msg.Priority)));
            memo1.Lines.Append('Datum: '+datetostr(Msg.Date));
            memo1.Lines.Append('Uhrzeit: '+TimeTostr(Msg.Date));
            memo1.Lines.Append('------------------------------------------');


            
                //Anhang
                for i := 0 to Msg.MessageParts.Count-1 do begin
                  if Msg.MessageParts.Items[i] is tIdAttachment then
                      begin
                        s := (Msg.MessageParts.Items[i] as tIdAttachment).Filename;
                        memo1.Lines.Append('Anhang: '+s);
                       (Msg.MessageParts.Items[i] as tIdAttachment).savetofile(ExtractFilePath(Application.ExeName) +'/Mails/Anhang_' + IntToStr(intIndex) +s);
                      end;
                end;


                // HTML Mail
                if msg.MessageParts.Count > 0 then
                begin
                memo1.Lines.Add('HTML-Mail:');
                for i := 0 to Msg.MessageParts.Count-1 do begin
                    if Msg.MessageParts.Items[i] is TIdText then
                     begin
                      memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[i]).Body);
                      TIdText(Msg.MessageParts.Items[i]).Body.SaveToFile(ExtractFilePath(Application.ExeName) +'/Mails/html_' + IntToStr(intIndex) + '.html');
                     end;
                end;
                end;


                // Text Mail
                if msg.MessageParts.Count =0 then
                begin
                memo1.Lines.Add('TXT-Mail:');
                  memo1.Lines.AddStrings(msg.body);
                  Msg.Body.SaveToFile(ExtractFilePath(Application.ExeName) +'/Mails/text_' + IntToStr(intIndex) + '.txt');
                end;



            memo1.Lines.Append('------------------------------------------');
            memo1.Lines.Append('');
            memo1.Lines.Append('');
            memo1.Lines.Append('');



      end;
      end;
      POP.Disconnect;



end;

end.
Erich Wanker - for life:=1971 to lebensende do begin ..
O
/H\
/ \

Geändert von erich.wanker (28. Jun 2012 um 11:34 Uhr)
  Mit Zitat antworten Zitat
 


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 06:28 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 by Thomas Breitkreuz