Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Principal > Internet
Register FAQ Members List Calendar Guía de estilo Search Today's Posts Mark Forums Read

Colaboración Paypal con ClubDelphi

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
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í:

Code:
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:
Code:
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:
Quote:
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:
Code:
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:
Quote:
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?
Reply With Quote
  #2  
Old 04/02/2021
Casimiro Noteví's Avatar
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Join Date: Sep 2004
Location: En algún lugar.
Posts: 32,702
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Deberás cambiar 'text/plain' por html.
Echa un vistazo por los foros, se ha tratado varias veces antes.
Reply With Quote
  #3  
Old 05/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
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:
Quote:
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.
Reply With Quote
  #4  
Old 05/02/2021
Casimiro Noteví's Avatar
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Join Date: Sep 2004
Location: En algún lugar.
Posts: 32,702
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Echa un vistazo a este hilo.
Y este también.
Y este otro.
Reply With Quote
  #5  
Old 05/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
Angel.Matilla Va por buen camino
Gracias. Lo miraré.
Reply With Quote
  #6  
Old 06/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
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í:
Code:
TIdText *Texto;
Texto = new TIdText(MenCor->MessageParts);
siendo MenCor un TidMessage, pero al compilar me da este error:
Quote:
[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:
Quote:
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:
Code:
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?
Reply With Quote
  #7  
Old 06/02/2021
Casimiro Noteví's Avatar
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Join Date: Sep 2004
Location: En algún lugar.
Posts: 32,702
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví 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?
Reply With Quote
  #8  
Old 07/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
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.
Reply With Quote
  #9  
Old 08/02/2021
juanelo's Avatar
juanelo juanelo is offline
Miembro
 
Join Date: Sep 2007
Posts: 1,087
Poder: 21
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="[email protected]";
    CC = "[email protected]";
    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!

Last edited by juanelo : 08/02/2021 at 18:24.
Reply With Quote
  #10  
Old 09/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
Angel.Matilla Va por buen camino
Gracias por la ayuda. Lo probaré en cuanto pueda.
Reply With Quote
  #11  
Old 09/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
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:
Quote:
E2352 Cannot create instance of abstract class 'TIdAttachment'
¿No debería ser new TIdAttachmentFile?
Reply With Quote
  #12  
Old 09/02/2021
juanelo's Avatar
juanelo juanelo is offline
Miembro
 
Join Date: Sep 2007
Posts: 1,087
Poder: 21
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!
Reply With Quote
  #13  
Old 11/02/2021
Angel.Matilla's Avatar
Angel.Matilla Angel.Matilla is offline
Miembro
 
Join Date: Jan 2007
Location: Toledo - España
Posts: 1,418
Poder: 21
Angel.Matilla Va por buen camino
Yop tengo la 10.6.2.0. Seguiré investigando. Gracias.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Propiedades para un TIdSMTP Angel.Matilla Internet 0 03/02/2021 12:47
Tiempo de respuesta de TIdSmtp Angel.Matilla C++ Builder 2 20/02/2018 13:09
Problemas para enviar un e-mail con el TIdSMTP Mauro® Internet 8 17/06/2010 18:29
Timeout de TIdsmtp mjjj Internet 0 11/01/2010 21:10
Enviar correo TIDSMTP mjjj Varios 1 08/08/2008 17:32


All times are GMT +2. The time now is 12:35.


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