Hola, te paso la formar en que yo lo hice a ver si te ayuda (no sé si cambia algun nombre o propiedad de los componentes ya que yo lo hice con las Indy8):
Saludos
Código Delphi
[-]
with idMessage1 do begin
Body.Clear;
MessageParts.Clear;
ContentType := 'text/html';
with TIdText.Create(IdMessage1.MessageParts, nil) do begin
Body.LoadFromFile(edFileName.Text); ContentType := 'text/html';
end;
From.Address := FieldByName('CE_DIRECCION').AsString;
From.Name := FieldByName('CE_NOMBRE').AsString;
ReplyTo.EMailAddresses := FieldByName('CE_RESPUESTA').AsString;
Subject := edAsunto.Text;
Priority := TidMessagePriority(mpHighest);
end;
with idSMTP1 do begin
AuthenticationType := atLogin;
UserId := FieldByName('CE_SMTP_USERID').AsString; Password := FieldByName('CE_SMTP_PASSWORD').AsString; Host := FieldByName('CE_SMTP').AsString;
Port := 25;
try
Connect;
try
Estado := 'Enviando emails...';
With DM, QResult do begin
FetchAll;
pbProgreso.Max := RecordCount;
if chkDestinatarios.Checked then
MaxDestinatarios := Trunc(edMaxDest.Value)
else
MaxDestinatarios := RecordCount;
idMessage1.Recipients.EMailAddresses := idMessage1.ReplyTo.EMailAddresses;
idMessage1.BccList.Clear;
First;
While not EOF do begin
pbProgreso.Position := RecNo;
pbProgreso.Refresh;
if ValidaEmail(FieldByName('email').AsString) then
With idMessage1, BCCList do begin
Add.Address := Trim(FieldByName('email').AsString);
if Count = MaxDestinatarios then begin
EnviaEmail;
BCCList.Clear;
end;
end;
Next;
end;
With idMessage1, BccList do
if Count > 0 then EnviaEmail;
end;
Estado := 'Desconectando...';
finally
Disconnect;
Screen.Cursor := crDefault;
end;
except
ON E: EIdProtocolReplyError do begin
ShowMessage('No se ha podido enviar el email.' + #13 +
'Incorrecto el email o el usuario o la password.' + #13 +
E.Message + #13 + idMessage1.BccList.EMailAddresses);
end;
on E: EFOpenError do begin
ShowMessage('No se ha podido enviar el email.' + #13 +
'Fichero Adjunto desconocido o erróneo.');
end;
on E: EIdSocketError do begin
ShowMessage('No se ha podido enviar el email.'+ #13 +
'Host desconocido o incorrecto.');
end
else begin
ShowMessage('Fallo en el envio de email');
end;
end;
if connected then Disconnect;
end;