Einzelnen Beitrag anzeigen

berens

Registriert seit: 3. Sep 2004
431 Beiträge
 
Delphi 2010 Professional
 
#9

AW: EMail über Outlook 2003 versenden

  Alt 20. Aug 2013, 19:27
Beispiel für SENT / Gesendete Objekte mit den OfficePartner Komponenten für Outlook:

Delphi-Quellcode:
       
var
  InBox: TInbox;
  MailItem: TMapiMailItem;
  FOpOutlook: TOpOutlook;

  oMAPIFolder: MAPIFolder;
  oItems: Items;

  oMail: _MailItem;
  oMailItem: TOpMailItem;
  sfilter: string;

begin
  if not FopOutlook.Connected then FopOutlook.Connected := True;

        // Post-Eingang
        oMAPIFolder := FopOutlook.MapiNamespace.GetDefaultFolder(olFolderInbox);
        if assigned(oMAPIFolder) then begin
          // Nur die letzten 14 Tage anbieten
          oItems := oMAPIFolder.Items;
          sFilter := '[SentOn] >'''+ DateToStr(floor(now-14)) + '''';
          oItems := oItems.Restrict(sfilter);

          if oItems.Count > 0 then begin
            for i := 1 to oItems.Count do begin // Items uses a 1 based index

              if oItems.Item(i).QueryInterface( _MailItem, oMail ) = s_OK then begin
                oMailItem := TOpMailItem.Create( oMail );

                tmpMail := TMail.Create(NIL); // <-- Mail ist eine Klasse von mir
                tmpMail.EntryID := oMailItem.MailItem.EntryID;
                tmpMail.slContacts.Add(GetSenderEMailByEntryID(tmpMail.EntryID));
                tmpMail.Subject := oMailItem.Subject;
                tmpMail.Body := oMailItem.Body;
                tmpMail.SentOn := oMailItem.MailItem.SentOn;
                tmpMail.Richtung := riEingehend;
                FclMail.Add(tmpMail);

                FreeAndNil(oMailItem);
              end;
            end;
          end;
        end;
      end;
  Mit Zitat antworten Zitat