Solved

Outlook 2003 inbox messages read

Posted on 2004-03-26
10
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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