Ver Mensaje Individual
  #6  
Antiguo 04-08-2014
JuanHC JuanHC is offline
Miembro
 
Registrado: sep 2006
Posts: 25
Reputación: 0
JuanHC Va por buen camino
Hola,

Por si os sirve de algo. Adjunto el codigo que yo utilizo y funciona bien enviando adjuntos.

Me pasaba algo parecido, si el mail no tenia adjuntos, se veia bien, pero si tenia adjunto, lo indicaba pero no se veia.
El cambio que hice fue:

NO tiene adjunto: compMensaje.ContentType := 'text/html' ;
SI tiene adjunto: compMensaje.ContentType := 'multipart/mixed' ;

y me funciona bien.



function TFmails.enviarEmail(servidor : string; usuario : string; contrasena : string;
puerto : integer; asunto : string; mensaje : TStringList; conAutenticacion : boolean;
emisor : string; nombreEmisor : string; destinatario : string; cc : string) : boolean;
var
compMensaje : TIdMessage;
envioCorrecto : boolean;
var Linea: string ;
var b, FlagAdjuntos: Integer;
begin
if conAutenticacion then
begin
compEnvioEmail.AuthType := satDefault;
compEnvioEmail.Username := usuario;
compEnvioEmail.Password := contrasena;
end
else
compEnvioEmail.AuthType := satNone;

compMensaje := TIdMessage.Create (nil);
compMensaje.From.Address := emisor;
compMensaje.From.Name := nombreEmisor;
compMensaje.Recipients.Add.Address := destinatario;
if Trim(cc) <> '' then compMensaje.CCList.Add.Address := cc;
compMensaje.ContentType := 'text/html' ;
compMensaje.CharSet := 'iso-8859-1' ;
compMensaje.Subject := asunto;
compMensaje.ReplyTo.Add.Address := emisor;


FlagAdjuntos := 0 ;
ListaAdjuntos := Trim(ListaAdjuntos) + ';';
if Length(ListaAdjuntos) > 1 then
begin
i := 1 ;
while ( i <= 10 ) do
begin
nFicheros[i] := '' ;
ListaAdjuntos := Trim(ListaAdjuntos);
Largo := Length(ListaAdjuntos) ;
Posicion := Pos(';', ListaAdjuntos);

if Posicion > 0 then
begin
FlagAdjuntos := 1 ;
nFicheros[i] := Copy(ListaAdjuntos, 1,Posicion-1);
ListaAdjuntos := Copy(ListaAdjuntos, Posicion+1, Largo+Posicion) ;
TIdAttachmentFile.Create(compMensaje.MessageParts, Trim(nFicheros[i]));
end;
i := i + 1;
end;
end;

if FlagAdjuntos = 1 then compMensaje.ContentType := 'multipart/mixed' ;

for b:=0 to mensaje.count -1 do
begin
if FlagAdjuntos = 1 then Linea := mensaje[b] else Linea := mensaje[b] + '<BR>';
compMensaje.Body.Add(Linea);
end;


envioCorrecto := true;
try
compEnvioEmail.Send(compMensaje);
except
envioCorrecto := false;
end;

TIdAttachment.NewInstance.Free ;
compMensaje.Free;
enviarEmail := envioCorrecto;
end;
Responder Con Cita