![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
||||
|
||||
|
Problema con envio de correos con fichero adjunto
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;
Un saludo. |
|
#2
|
||||
|
||||
|
Hola, yo no lo hago exactamente así, no sé si será por la versión de las Indy.
Prueba de esta manera:
Saludos
__________________
Be water my friend. |
|
#3
|
||||
|
||||
|
He probado y si gue sin funcionar.
Supongo que la diferencia que me propones es no asignar la creación deTIdAttachmentFile a una variable? |
|
#4
|
||||
|
||||
|
Hola de nuevo.
Este es mi código y funciona
Mira a ver si puedes probar con esto.
__________________
Be water my friend. |
|
#5
|
||||
|
||||
|
Ya Está !!!
Solo he comentado las lineas "Mensaje.ContentType" y funcionó a la primera. Gracias por tu ayuda. ![]() |
|
#6
|
||||
|
||||
|
Pues fíjate que pensé en decirte que hicieras eso pero pensé..."mejor se lo mando completo y no damos muchos cabezazos".
Me alegro que ya te funcione. Saludos
__________________
Be water my friend. |
![]() |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Error en envío de mail con adjunto + Indy 10 | agustibaldo | Internet | 8 | 23-01-2015 21:23:31 |
| ?Envio de correos ? | jasmad | Lazarus, FreePascal, Kylix, etc. | 16 | 02-10-2012 15:45:02 |
| Capturar error envio de correos con el evento OnFailedRecipient | arante73 | Internet | 0 | 17-07-2007 10:05:54 |
| Envio de Correos Masivo | Esau | Internet | 2 | 10-04-2007 01:46:11 |
| Obtener un fichero adjunto a un nodo de un fichero XML | muntasil | Internet | 0 | 18-07-2006 12:57:57 |
|