Avatar of aliahmedali
aliahmedali

asked on 

Outlook 2003 inbox messages read

hi experts,

I would like an Outlook 2003 application that will iterate through e-mail messages in the inbox and extract all of the e-mail addresses found in these mails.

any body knows how
Delphi

Avatar of undefined
Last Comment
shaneholmes
Avatar of shaneholmes
shaneholmes

You want the addresses just from the FROM or from the message BODY, TO: BCC: etc

SHane
Avatar of shaneholmes
shaneholmes

This example uses the TOutLookApplication (Servers tab on component pallette)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleServer, OutlookXP;

type
  TForm1 = class(TForm)
    OutlookApplication1: TOutlookApplication;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.

procedure FormShow;
var
 i: Integer;
 NmSpace: NameSpace;
 Folder: MAPIFolder;
 itm: Variant;
 criteria: String;
 itms: MailItem;
 objMsg: ContactItem;
begin
 OutlookApplication1.Connect;
 NmSpace := OutlookApplication1.GetNamespace('MAPI');
 NmSpace.Logon('', '', False, False);
 Folder := NmSpace.GetDefaultFolder(olFolderInbox);
 For i:= 1 to Folder.Items.Count do
 begin
  itms := Folder.Items.Item(i) As MailItem;
  ShowMessage(Items.SenderName);
 end;
end;

end.
Avatar of shaneholmes
shaneholmes

Sorry, Im very tired..... here it is tested

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleServer, OutlookXP;

type
  TForm1 = class(TForm)
    OutlookApplication1: TOutlookApplication;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.FormShow(Sender: TObject);
var
 i: Integer;
 NmSpace: NameSpace;
 Folder: MAPIFolder;
 itm: Variant;
 criteria: String;
 itms: MailItem;
 objMsg: ContactItem;
begin
 OutlookApplication1.Connect;
 NmSpace := OutlookApplication1.GetNamespace('MAPI');
 NmSpace.Logon('', '', False, False);
 Folder := NmSpace.GetDefaultFolder(olFolderInbox);
 For i:= 1 to Folder.Items.Count do
 begin
  itms := Folder.Items.Item(i) As MailItem;
  //now you have access to all these
  {itms.SenderName}
  {itms.CC}
  {itms.BCC}
  {itms.Subject}
  {itms.Body}
 end;
end;

end.
Avatar of shaneholmes
shaneholmes

man......im getting tired.....i forgot to add the list of addresses to collect

Shane

procedure TForm1.FormShow(Sender: TObject);
var
 i: Integer;
 NmSpace: NameSpace;
 Folder: MAPIFolder;
 itm: Variant;
 criteria: String;
 itms: MailItem;
 objMsg: ContactItem;
 Addresses: TStringList; //***
begin
 Addresses:= TStringList.Create; //***
 OutlookApplication1.Connect;
 NmSpace := OutlookApplication1.GetNamespace('MAPI');
 NmSpace.Logon('', '', False, False);
 Folder := NmSpace.GetDefaultFolder(olFolderInbox);
 For i:= 1 to Folder.Items.Count do
 begin
  itms := Folder.Items.Item(i) As MailItem;
  //now you have access to all these
  {itms.SenderName}
  {itms.CC}
  {itms.BCC}
  {itms.Subject}
  {itms.Body}
  Addresses.Add(itms.SenderName); //***
  //do somthing with these addresses
 end;
 Addresses.Free; ////***
end;
Avatar of aliahmedali
aliahmedali

ASKER

i dont only to get the from i also want to open the mail message -mail body - itself and extract all the mails.

i want to nkow how to read  the mail body.

thanx
ASKER CERTIFIED SOLUTION
Avatar of shaneholmes
shaneholmes

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of shaneholmes
shaneholmes

sorry, it looks like it may be like

P:= Pos('@', ALine)
while P <> -1 do


Shane
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo