was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

24 Visitors Online


 
...von Outlook Attachments ein Backup erstellen?
Autor: Patrick Cleys
Homepage: http://www.dcmedical.org
[ Tip ausdrucken ]  

Tip Bewertung (14):  
     


{
  Won’t some backups of your outlook attachments are filtered
  some incoming log files? Here's the function.
}

uses
  
ComObj;

{...}

function ManageAttachments(SendersName, AttachmentPath: string;
  MailDelete: Boolean): Boolean;
var
  
oApp: Variant;
  oNs: Variant;
  oFolder: Variant;
  oMsg: Variant;
  AtC: Variant;
  AttFilename: Variant;
  FileName: string;
  CheckSender: string;
  Counter: integer;
  MailCounter: integer;
begin
  try
    
oApp := CreateOLEObject('outlook.application');
    try
      
oNs         := oApp.GetNamespace('MAPI');
      ofolder     := oNS.GetDefaultFolder(6); // FolderTypeEnum  (olFolderInbox)
      
MailCounter := 1;
      // If there is any email in the Inbox
      
if ofolder.Items.Count > 0 then
      begin
        repeat
          
// Get the first Email
          
oMsg := ofolder.Items(MailCounter);
          // Check the name or Email
          //   Use CheckSender := oMsg.subject to search on Subject;
          
CheckSender := oMsg.sendername;
          if CheckSender = SendersName then
          
//  Remove this line to backup all your attachments.
          
begin
            
// Check how many attachments
            
atc := oMsg.Attachments.Count;
            if atc > 0 then
            begin
              
// Get all the attachments and save them
              
for Counter := 1 to atc do
              begin
                
AttFilename := oMsg.Attachments.item(Counter).FileName;
                //filename := IncludeTrailingBackslash(AttachmentPath)+AttFilename; {Use this line for D5)}
                
FileName := AttachmentPath + '\' + AttFilename;
                oMsg.Attachments.Item(Counter).SaveAsFile(FileName);
              end;
            end;
            if MailDelete then
            begin
              
oMsg.Delete;
              // There's 1 Email less, so MailCounter - 1
              
Dec(MailCounter);
            end;
          end;
          // Get the next Email
          
Inc(MailCounter);
          // Do until there is no more Email to check
        
until MailCounter > ofolder.Items.Count;
      end;
    finally
      
oApp.quit;
    end;
  except
    
Result := False;
    Exit;
  end;
  Result := True;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  
// ManageAttachments(Email or name, Backup directory, MailDelete yes or no)
  
ManageAttachments('info@cleys.com', 'F:\test', False);
end;


{
  Warning!
  All your selected Email will be deleted if MailDelete = true

  Achtung!
  Alle E-Mails werden gelöscht, wenn MailDelete = true ist.
}


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners