Aquí te paso la función entera:
Código:
{/* FUNCION CON LA QUE REALIZAMOS EL ENVIO DEL CORREO A LA CUENTA INDICADA POR
EL USUARIO. */}
function TForm_InfEmail.EnviaCorreo(Fichero : String):Boolean;
var cad: string;
SMTP, Usuario, eCorreo: String;
begin
{/* EXTRAEMOS DE LA TABLA DE CONFIGURACIÓN LOS PARAMETROS PARA EL
ENVIO DE CORREO ELECTRÓNICO */}
ModuloDatos.ConsultaSQL(' SELECT CEMAIL, CSMTP, CUSUARIO FROM CONFIGURACION ',1);
eCorreo := ModuloDatos.CamposSQL[0];
SMTP := ModuloDatos.CamposSQL[1];
Usuario := ModuloDatos.CamposSQL[2];
{/* Creamos la lista de Adjuntos e inicializamos la variable EMAILCORRECTO a
Falso. */}
EMailCorrecto := False;
LabAccion3.Caption := 'Preparando...';
{/* Le damos los valores necesarios al componente NMSMTP1. */}
with NMSMTP1 do begin
Host := SMTP; {/* IP del dominio de la cuenta. */}
UserID := Usuario; {/* Usuario de dicha cuenta. */}
LabAccion3.Caption := 'Enviando...' ;
Application.ProcessMessages;
PostMessage.Attachments.Text := Fichero; {/* Array de adjuntos. */}
PostMessage.FromAddress := eCorreo; {/* Correo origen. */}
PostMessage.ToAddress.Text := trim(Email.Text); {/* Correo destino. */}
PostMessage.Subject := trim(Asunto.Text); {/* Asunto del correo. */}
PostMessage.ToCarbonCopy.Text := '';
PostMessage.ToBlindCarbonCopy.Text := '';
PostMessage.Body.Text := '';
try
SendMail; {/* Mandamos el correo. */}
Except
On E: Exception do begin {/* Si falla mostramos un mensaje en pantalla. */}
Cursor := crDefault;
ModuloDatos.MensaErr(165,CodPantalla,'No se pudo enviar el correo a su destino. Se provocó el siguiente error:'
+ #13#10 + #13#10 +
'--> ' + E.Message);
LabAccion3.Caption := '¡¡¡ FALLIDO !!!' ;
Application.ProcessMessages;
end;
end;
end;
Result := EMailCorrecto;
end;