Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Outlook 2003 inbox messages read

Posted on 2004-03-26
10
Medium Priority
?
295 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
Technology Partners: 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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