title: How can I use Indy to send messages to multiple email addresses that are stored within a TListView component?
body: <p>I am trying to take a list of emails from within a <code>TListView</code> and assign them to <code>TIdMessage.Recipients.EMailAddresses</code>. I'm trying to take the ListView captions and assign them as recipient email addresses, however I cannot work out how to do it.</p>
  <p>Here is my currently broken code:</p>
  <pre class="lang-pascal prettyprint-override"><code>procedure TfrmEmailer.btnSendClick(Sender: TObject);
  var
    smtpServer: TIdSMTP;
    msgEmail: TIdMessage;
    ssl: TIdSSLIOHandlerSocketOpenSSL;
    i: integer;
  
  begin
    smtpServer := TIdSMTP.Create(nil);
    msgEmail := TIdMessage.Create(nil);
    ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  
    ssl.SSLOptions.Method := sslvTLSv1_2;
    ssl.SSLOptions.Mode := sslmUnassigned;
    ssl.SSLOptions.VerifyMode := [];
    ssl.SSLOptions.VerifyDepth := 0;
  
    msgEmail.Sender.Address := edtSenderAddress.Text;
    msgEmail.Sender.Name := edtSenderName.Text;
    msgEmail.ReplyTo.EMailAddresses := edtReplyTo.Text;
    for i := 0 to length(lsvRecipients.ItemIndex) do
    begin
      msgEmail.Recipients.EMailAddresses := lsvRecipients.Items[0].Caption;
    end;
  
    msgEmail.Subject := edtSubject.Text;
    msgEmail.Body.Text := redBody.Text;
  
    smtpServer.IOHandler := ssl;
    smtpServer.Host := edtHost.Text;
    smtpServer.Port := StrToInt(edtPort.Text);
    smtpServer.Username := edtUsername.Text;
    smtpServer.Password := edtPassword.Text;
    smtpServer.UseTLS := utUseExplicitTLS;
  
    smtpServer.Connect;
    smtpServer.Send(msgEmail);
    smtpServer.Disconnect;
  
    smtpServer.Free;
    msgEmail.Free;
    ssl.Free;
  
    // Output
    beep;
    ShowMessage('Email Sent!');
  end;
  
  procedure TfrmEmailBomber.btnAddEmailClick(Sender: TObject);
  begin
    emailToAdd := lsvRecipients.Items.Add;
    emailToAdd.Caption := edtAddEmail.Text;
  end;
  </code></pre>