Solved

Outlook 2003 inbox messages read

Posted on 2004-03-26
10
281 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:aliahmedali
  • 6
10 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10692197
You want the addresses just from the FROM or from the message BODY, TO: BCC: etc

SHane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10692258
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.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10692309
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10692329
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;
0
 

Author Comment

by:aliahmedali
ID: 10693851
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
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 150 total points
ID: 10694598


You will have to parse the  the entire body for @ symbol

To get the body of the message use exactly what i showed you above


itms.body

you can place it in a stringlist like

MyStringList.Text:= itms.body;

then you got to step through each line of the stringlist to parse it out for emails

This would be very tough though, seeing that there could be more than one email address per line.

However, this is of the top of my head, this is not tested, something like

 var
 I,J,  Start, End, P: Integer;
 ALine: String;

 //step through each line
 for I:= 0 to Mystringlist.count - 1 do
 begin
  //get the line
  ALine:= MyStringList[I];
  while P <> -1 do
  begin
   // get the position of '@'
    P:= Pos('@', ALine)
   // move backwards and look for space
    for J:= P to 0 do
     if ALine[J] = ' ' then
     begin
      Start:= J + 1;
      Break;
     end;
    //now move forward and look for space
    for J:= Start to ALine.Length to
     if ALine[J] = ' ' then
     begin
      End:= J - 1;
      Break;
     end;
  // add email address to list
   Addresses.add(Copy(ALine,Start,End));
  //delete email address from Line
   Delete(ALine,Start,End));
   end; //while {repeat until no more email addresses on line
 end; //for {repeat until all lines hva ebeen stepped through
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10694603
sorry, it looks like it may be like

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


Shane
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now