Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Problems adding more than one recipient to a TIdMessage

www.cryer.info
Managed Newsgroup Archive

Problems adding more than one recipient to a TIdMessage

Subject:Problems adding more than one recipient to a TIdMessage
Posted by:"Paul Coshott" (pa..@pacsoftware.com.au)
Date:Thu, 13 Dec 2007 15:59:14

Hi All,

I am using the following code to add email addresses that are comma or semi
colon separated.

      with IdMessage1.Recipients.Add do begin
        sEMailRecip := strReplace(tblCustEMail.AsString, ',', ';');
        if Pos(';', sEMailRecip) = 0 then begin
          Address := strTrim(sEMailRecip);
          Name := strTrim(sEMailRecip);
        end else begin
          zEMailLeft := sEMailRecip;
          while zEMailLeft <> '' do begin
            if Pos(';', zEMailLeft) = 0 then begin
              Address := strTrim(zEMailLeft);
              Name := strTrim(zEMailLeft);
              zEMailLeft := '';
            end else begin
              zEMail := strLeft(zEMailLeft, Pos(';', zEMailLeft)-1);
              Address := strTrim(zEMail);
              Name := strTrim(zEMail);
              zEMailLeft := strRight(zEMailLeft, Length(zEMailLeft)-Pos(';',
zEMailLeft));
            end;
          end; //while
        end;
      end;

Firstly, is there an easier way to add a comma or semi colon separated list
of emails to the Recipients property of the TIdMessage component?

If not, the problem I am having is the last email address added is the only
one in the Recipients list. For example, if the email address string
contains :

abc@westnet.com.au, efg@westnet.com.au, xyz@westnet.com.au

and after the code above has run, in the debugger I look at
IdMessage1.Recipients.Items[0], it contains
'xyz@westnet.com.au','xyz@westnet.com.au'
It seems the Add method is not adding a new one each time, but is
overwriting the previous one.

Any ideas what I am doing wrong ?

Cheers,
Paul

Replies:

www.cryer.info
Managed Newsgroup Archive