estoy intentando mandar correos con ficheros adjuntos y me envia correctamente el correo pero el adjunto no.
Utilizo esto código:
Código:
procedure TCorreoSmtp.EnviarMail;
var SMTP: TIdSMTP;
Mensaje: TIdMessage;
Adjunto: TIdAttachmentFile;
i: integer;
begin
if trim(EDestinatario.Text)='' then begin
Showmessage('Debe especificarse un destinatario');
Exit;
end;
SMTP := TIdSMTP.Create( nil );
SMTP.Username := sUsuario;
SMTP.Password := sClave;
SMTP.Host := sHost;
try
SMTP.Port := strtoint(sPort);
except
SMTP.Port := 25;
end;
SMTP.AuthType := satDEFAULT; //satNONE, satDEFAULT, satSASL
Mensaje := TIdMessage.Create( nil );
Mensaje.Clear;
Mensaje.ReplyTo.EMailAddresses := sReplyTo;
with TIdText.Create(Mensaje.MessageParts, nil) do begin
for i := 0 To Memo.Lines.Count -1 do
SMensaje := SMensaje + '<br>' + Memo.Lines[i];
Body.Text := sMensaje;
ContentType := 'text/html';
end;
Mensaje.From.Name := sFromNome;
Mensaje.From.Address := sFromEmail;
Mensaje.Subject := sAsunto;
if trim(sCopia)<>'' then begin
Mensaje.BccList.Add;
Mensaje.BccList.Items[0].Address := sCopia;
end;
Mensaje.Recipients.Add;
Mensaje.Recipients.Items[0].Address := sDestino;
if (sAdjunto <> '') and (FileExists( sAdjunto )) then begin
Adjunto := TIdAttachmentFile.Create(Mensaje.MessageParts, sAdjunto);
Mensaje.ContentType := 'multipart/related';
end else begin
Adjunto := nil;
Mensaje.ContentType := 'multipart/alternative';
end;
try
SMTP.Connect;
except
raise Exception.Create( 'Error al conectar con el servidor' );
end;
if SMTP.Connected then
begin
try
SMTP.Send( Mensaje );
except
raise Exception.Create( 'Error al enviar el mensaje.' );
end;
try
SMTP.Disconnect;
except
raise Exception.Create( 'Error al desconectar del servidor.' );
end;
end;
if Adjunto <> nil then
FreeAndNil( Adjunto );
FreeAndNil( Mensaje );
FreeAndNil( SMTP );
end;
Alguien ve algo raro en este código?
Un saludo.