Title: How to retrieve real email addresses from Outlook From Inbox mails
Question: How to retrieve real email addresses from Outlook From Inbox mails
Answer:
I'd like to thank my friend Gilles Urbain who helped me to get it !
You can find him at gilles.urbain@automotive.be.tnsofres.com
unit UMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComObj, Outlook_TLB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox3: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
MyOutlook : _Application;
MyNameSpace : _NameSpace;
MyFolder : MAPIFolder;
MyMail, MyReply : _MailItem;
MailRecipients, ReplyRecipients : Recipients; // !! Collection !!
ARecipient : Recipient; // !! Item !!
i, j : Integer;
seMailAddress : String;
begin
MyOutlook := CoOutlookApplication.Create;
Try
MyNameSpace := MyOutlook.GetNamespace('MAPI');
MyFolder := MyNameSpace.GetDefaultFolder(olFolderInbox);
For i := 1 to MyFolder.Items.Count do
Begin
MyMail := (MyFolder.Items.Item(i) As _MailItem);
// Comme nous voulons rcuprer l'adresse email relle de l'expditeur.
// As we want retrieve the real Sender email address.
MyReply := MyMail.Reply;
MailRecipients := MyMail.Recipients;
ReplyRecipients := MyReply.Recipients;
ListBox3.Items.BeginUpdate;
// Rcupration de toutes les adresses email relles des personnes
// en copie.
// Retrieve ALL CC real email addresses.
for j := 1 to MailRecipients.Count do
Begin
ARecipient := MailRecipients.Item(j);
seMailAddress := ARecipient.Address;
If Pos('@',seMailAddress) 0 Then
ListBox3.Items.Append(seMailAddress);
End;
// Rcupration de l'adresse email relle de l'expditeur.
// Retrieve the real Sender email address.
for j := 1 to ReplyRecipients.Count do
Begin
ARecipient := ReplyRecipients.Item(j);
seMailAddress := ARecipient.Address;
If Pos('@',seMailAddress) 0 Then
ListBox3.Items.Append(seMailAddress);
End;
ListBox3.Items.EndUpdate;
End;
Finally
MyOutlook.Quit;
End;
end;
end.