Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 04-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Problemas con TIdSMTP

Buenas otra vez; aquí está de nuevo el pesado de turno.

Tengo, como ya sabéis, una aplicación hecha en BCB6 con una base de datos FB y estoy teniendo un problema al enviar correos desde la misma para lo que uso un TIdMessage, asociado a un TIdSMTP, (ver. 10.6.2.0) que tengo definido así:

Código:
Mensaje->AttachmentEncoding = 'UUE'
Mensaje->CharSet = 'iso-8859-1'
Mensaje->ContentType = 'text/plain'
Mensaje->Encoding = mePlainText
Mensaje->ConvertPreamble = True
El usuario me ha pedido incluir en los mensajes su logotipo como firma y en principio creía que no había mayor problema, que bastaba con incluirlo como adjunto y listo. Pero no he encontrado la manera de incluir ese logotipo en el mensaje de forma que se haga legible. Sin envío el mensaje sin el logotipo, con este código:
Código:
Mensaje->MessageParts->Add();
Mensaje->Subject     = <Asunto>;
Mensaje->Body->Text  = <Cuerpo del mensaje>;
Mensaje->Body->Text = fMenu->MenCor->Body->Text + <Firma>;
Se envía sin mayor problema; por ejemplo:
Cita:
Esto es una prueba
Esto es una prueba
Esto es una prueba
Esto es una prueba
Esto es una prueba

-----

Atentamente,
Ángel
Pero si trato de "incrustar" una imagen (JPG) que haga de firma con este código:
Código:
TIdAttachmentFile *Firma  = new TIdAttachmentFile("Imagen.jpg");
Firma->ExtraHeaders->Values["Content-ID"] = "<imagen.jpg>";
Evidentemente, el logo ya lo tengo guardado en un fichero. Lo que obtengo es esto:
Cita:
Esto es una prueba
Esto es una prueba
Esto es una prueba
Esto es una prueba

-----

Atentamente,
Ángel

begin 660 Imagen.jpg
M_]C_X``02D9)1@`!`0```0`!``#_VP!#``,"`@,"`@,#`P,$`P,$!0@%!00$
[...]
end
Yo sé que todo eso que hay entre el begin y el end es la imagen pero ¿cómo hago para que se vea en el mensaje?
Responder Con Cita
  #2  
Antiguo 04-02-2021
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.040
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Deberás cambiar 'text/plain' por html.
Echa un vistazo por los foros, se ha tratado varias veces antes.
Responder Con Cita
  #3  
Antiguo 05-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Estaba convencido de que lo había probado... y así es. Si pongo text/html esto es lo que recibo:
Cita:
Esto es una prueba. Esto es una prueba. Esto es una prueba. Esto es una prueba. Esto es una prueba. ----- Atentamente, �ngel begin 660 Imagen.jpg M_]C_X``02D9)1@`!`0```0`!``#_VP!#``,"`@,"`@,#`P,$`P,$!0@%!00$ [...]end
Tal cual: sin retornos de carro ni nada.
Responder Con Cita
  #4  
Antiguo 05-02-2021
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.040
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Echa un vistazo a este hilo.
Y este también.
Y este otro.
Responder Con Cita
  #5  
Antiguo 05-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Gracias. Lo miraré.
Responder Con Cita
  #6  
Antiguo 06-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
He estado mirando los enlaces que me has mandado, y otros que encontré en el foro como Enviar mails con imágenes, y entiendo la filosofía de lo que explican. Pero me ha surgido un problema: como sabéis uso BCB 6 y me está costando adaptar el código Delphi. Hay una línea especialmente que se pone de uñas, esta:
Código Delphi [-]
lTextPart := TIdText.Create(lMessage.MessageParts);
Si trato de adaptarla a Builder entiendo que debería ser algo así:
Código:
TIdText *Texto;
Texto = new TIdText(MenCor->MessageParts);
siendo MenCor un TidMessage, pero al compilar me da este error:
Cita:
[C++ Error] Funciones.cpp(1310): E2285 Could not find a match for 'TIdText::TIdText(TIdMessageParts * const)'
En la ayuda del objeto me indica que la sintaxis sería:
Cita:
Create(Collection: TIdMessageParts; ABody: TStrings);
Parameters
Collection: TIdMessageParts
Owner of the collection item.

ABody: TStrings = nil
Content of the message part.
He probado también esto:
Código:
TIdText *iTexto;
TIdMessageParts *iMensaje;
iMensaje = new TIdMessageParts(MenCor);
iTexto = new TIdText(iMensaje);
pero me da el mismo error. ¿Podéis echarme una mano aunque sea un peado?
Responder Con Cita
  #7  
Antiguo 06-02-2021
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.040
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Mi C++ está muuuuuy oxidado, hace años que no lo uso. De todas formas, qué es lTextPart, lMessage, etc.
¿Qué código estás siguiendo?
Responder Con Cita
  #8  
Antiguo 07-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Estoy tomando como ejemplo el enlace que he puesto más arriba, que es en Delphi. lTextPart y lMessage son variables de ese ejemplo.
Responder Con Cita
  #9  
Antiguo 08-02-2021
Avatar de juanelo
juanelo juanelo is offline
Miembro
 
Registrado: sep 2007
Posts: 1.083
Poder: 18
juanelo Va por buen camino
Te mando este codigo que funciona :
Código Delphi [-]
bool __fastcall TFrmMail::EnviaMail()
{
  bool Que=true;
  int i=0,Intento=0;
  AnsiString Archivo,Imagen,Temp;
  TIniFile *Ini;



  ModuloDeDatos->LlenaListas(ListaPara,CorreoDestino,false);
  ModuloDeDatos->LlenaListas(ListaCC,CC,false);
  ModuloDeDatos->LlenaListas(ListaBCC,BCC,false);

  SMTP->Username = UserID;
  SMTP->Password = Password;
  SMTP->Host = Host;
  SMTP->Port = Port;
  SMTP->AuthenticationType = atLogin;
  if(UsaSSL)
    SMTP->IOHandler=SSL;

  if(UsaSTARTTLS)
  {
    SSL->SSLOptions->Method = sslvTLSv1;
    SSL->PassThrough = true;
  }
  // Creamos el contenido del mensaje
  Mensaje = new TIdMessage(NULL);

  Mensaje->Clear();

  Mensaje->ContentType = "multipart/mixed";

  Mensaje->From->Name = FromName;
  Mensaje->From->Address = FromAddress;
  Mensaje->Subject = Subject;
  //Mensaje->Body->Add(EdtBody->Text);

  
    Ini= new TIniFile( ModuloDeDatos->DirExe + "CorreoAdmin.ini");
    Host=Ini->ReadString("Correo","Host","");
    Port=Ini->ReadInteger("Correo","Port",26);
    UserID=Ini->ReadString("Correo","UserID","");
    FromAddress=Ini->ReadString("Correo","FromAddress","");
    FromName=Ini->ReadString("Correo","FromName","IDEA Sistemas Activaciones");
    PlantillaHTML=Ini->ReadString("Correo","PlantillaHTML","");
    Logo=Ini->ReadString("Correo","Logo","");
    TextoAdicional=Ini->ReadString("Correo","TextoAdicional","");
    UsaSSL=Ini->ReadBool("Correo","UsaSSL",false);
    UsaSTARTTLS=Ini->ReadBool("Correo","UsaSTARTTLS",false);
    delete Ini;

    CorreoDestino="juan.novelo@hotmail.com";
    CC = "juan.novelo@ideasistemas.mx";
    SMTP->Username = UserID;
    SMTP->Password = Pass;
  

  BodyIndyText = new TIdText(Mensaje->MessageParts,NULL);
  BodyIndyText->ContentType="text/plain";
  BodyIndyText->Body->Text="";

  Temp=EdtBody->Text;
  EdtBody->Text=EdtTextAdicional->Text + " 
" + EdtBody->Text; BodyIndyHtml = new TIdText(Mensaje->MessageParts,EdtBody->Lines); BodyIndyHtml->ContentType="text/html"; BodyIndyHtml->Body->Clear(); BodyIndyHtml->Body->Add(EdtBody->Text); if(FileExists(Logo)) { Imagen=ExtractFileName(Logo); LogoIndy = new TIdAttachment(Mensaje->MessageParts,Logo); LogoIndy->ContentType = "image/jpeg"; LogoIndy->FileIsTempFile = false; LogoIndy->ContentDisposition = "inline"; LogoIndy->ExtraHeaders->Values["content-id"] = Imagen; LogoIndy->DisplayName = Imagen; } while(i< ListaCC->Count) { Mensaje->CCList->Add(); Mensaje->CCList->Items[i]->Address=ListaCC->Strings[i]; i++; } i=0; while(i< ListaBCC->Count) { Mensaje->BccList->Add(); Mensaje->BccList->Items[i]->Address=ListaBCC->Strings[i]; i++; } i=0; while(i< ListaPara->Count) { Mensaje->Recipients->Add(); Mensaje->Recipients->Items[i]->Address=ListaPara->Strings[i]; i++; } if(CmbAttachs->Properties->Items->Count > 0 && FileExists(CmbAttachs->Properties->Items->Strings[0])) IndyAttach1 = new TIdAttachment( Mensaje->MessageParts, CmbAttachs->Properties->Items->Strings[0] ); if(CmbAttachs->Properties->Items->Count > 1 && FileExists(CmbAttachs->Properties->Items->Strings[1])) IndyAttach2 = new TIdAttachment( Mensaje->MessageParts, CmbAttachs->Properties->Items->Strings[1] ); if(CmbAttachs->Properties->Items->Count > 2 && FileExists(CmbAttachs->Properties->Items->Strings[2])) IndyAttach3 = new TIdAttachment( Mensaje->MessageParts, CmbAttachs->Properties->Items->Strings[2] ); if(CmbAttachs->Properties->Items->Count > 3 && FileExists(CmbAttachs->Properties->Items->Strings[3])) IndyAttach4 = new TIdAttachment( Mensaje->MessageParts, CmbAttachs->Properties->Items->Strings[3] ); // Conectamos con el servidor SMTP while(Intento < 2) { try { try { STB->Panels->Items[0]->Text="Conectando ... "; if(UsaSTARTTLS) SMTP->Connect(IdTimeoutDefault); else SMTP->Connect(); if(UsaSTARTTLS && SMTP->SendCmd("STARTTLS", 220) == 220)// se coloca PassThrough a false { SSL->PassThrough = false; SMTP->SendCmd("EHLO " + SMTP->LocalName); } if(SMTP->Connected()) { if(UsaSTARTTLS) SMTP->Authenticate(); STB->Panels->Items[0]->Text="Enviando correo ... "; SMTP->Send(Mensaje); Que=true; STB->Panels->Items[0]->Text="Desconectando ... "; SMTP->Disconnect(); STB->Panels->Items[0]->Text="Correo Enviado ... "; if(EsFactura || EsCPRN) MarcaFacturaEnviadaPorMail(CveDocto,EnviaXML,-1,TipoDoc); } Intento=2; PuedeCerrar=true; //DeleteFile(ModuloDeDatos->ArchivoPDF); } catch(Exception &e) { Que=false; if(e.Message.AnsiPos("load") == 0) // Por error de Indy { Intento=2; STB->Panels->Items[0]->Text="Error en el envio" + e.Message; //Application->MessageBox(e.Message.c_str(),"Error",MB_OK); } else Intento++; PuedeCerrar=false; } } __finally { if(SMTP->Connected()) SMTP->Disconnect(); if(Intento > 1) { if(IndyAttach1!=NULL) delete IndyAttach1; if(IndyAttach2!=NULL) delete IndyAttach2; if(IndyAttach3!=NULL) delete IndyAttach3; if(IndyAttach4!=NULL) delete IndyAttach4; if(LogoIndy!=NULL) delete LogoIndy; if(Mensaje!=NULL) delete Mensaje; EdtBody->Text=Temp; } } } return Que; }
__________________
Ya tengo Firma!

Última edición por juanelo fecha: 08-02-2021 a las 18:24:32.
Responder Con Cita
  #10  
Antiguo 09-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Gracias por la ayuda. Lo probaré en cuanto pueda.
Responder Con Cita
  #11  
Antiguo 09-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
if(FileExists(Logo))
{
Imagen=ExtractFileName(Logo);
LogoIndy = new TIdAttachment(Mensaje->MessageParts,Logo);
LogoIndy->ContentType = "image/jpeg";
LogoIndy->FileIsTempFile = false;
LogoIndy->ContentDisposition = "inline";
LogoIndy->ExtraHeaders->Values["content-id"] = Imagen;
LogoIndy->DisplayName = Imagen;
}
[/delphi][/quote]
Me está dando un error de compilación en la línea new TIdAttachment. me dice:
Cita:
E2352 Cannot create instance of abstract class 'TIdAttachment'
¿No debería ser new TIdAttachmentFile?
Responder Con Cita
  #12  
Antiguo 09-02-2021
Avatar de juanelo
juanelo juanelo is offline
Miembro
 
Registrado: sep 2007
Posts: 1.083
Poder: 18
juanelo Va por buen camino
Asi es Angel, lo que pasa es que te di codigo para la version 9.0.14 de Indy.
__________________
Ya tengo Firma!
Responder Con Cita
  #13  
Antiguo 11-02-2021
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Yop tengo la 10.6.2.0. Seguiré investigando. Gracias.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Propiedades para un TIdSMTP Angel.Matilla Internet 0 03-02-2021 12:47:52
Tiempo de respuesta de TIdSmtp Angel.Matilla C++ Builder 2 20-02-2018 13:09:37
Problemas para enviar un e-mail con el TIdSMTP Mauro® Internet 8 17-06-2010 18:29:27
Timeout de TIdsmtp mjjj Internet 0 11-01-2010 21:10:07
Enviar correo TIDSMTP mjjj Varios 1 08-08-2008 17:32:29


La franja horaria es GMT +2. Ahora son las 01:35:34.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi