?
Solved

Outlook 2003 inbox messages read

Posted on 2004-03-26
10
Medium Priority
?
294 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 600 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

718 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