-1

Using Indy, how can I extract all email addresses that are present in the To, Cc and Bcc fields of a TIdMessage? As these fields can contain more than one address, I must parse them, but I didn't find any ready-made function for that (maybe I've missed it?).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
zeus
  • 12,173
  • 9
  • 63
  • 184

1 Answers1

5

You obviously did not read the

TIdMessage documentation:

TIdMessage.BccList

TIdMessage.CCList

TIdMessage.Recipients
Identifies the recipients of a message.

property Recipients: TIdEmailAddressList;

Description
Recipients is a TIdEMailAddressList property used to store TIdEmailAddressItem values that identify the recipients of the message. Use CCList for recipients to receive a Carbon Copy of the message. Use BCCList for recipients to receive a Blind Carbon Copy of the message.

All of these properties give you a TIdEmailAddressList that you can harvest for addresses.

This is the second item in a google search for Indy TIdMessage.

For example:

function GetEmailAddresses(const Email: TIdMessage): TStringList;
var
  Item: TIdEmailAddressItem;
begin
  Result := TStringList.Create;
  for Item in Email.Recipients do Result.Add(Item.Address);
  for Item in Email.CcList do Result.Add(Item.Address);
  for Item in Email.BccList do Result.Add(Item.Address);
end;

Note that the Indy documentation uses the with keyword a lot.
Although convenient, using with is a very bad idea and I recommend you avoid it at all costs.

Community
  • 1
  • 1
Johan
  • 74,508
  • 24
  • 191
  • 319
  • thanks johan i miss it :( but i do not use anymore google because of privacy problem with google ;) and i use maybe wrong keyword on stackoverflow ! anyway thanks a lot – zeus Sep 27 '16 at 21:16