Ver Mensaje Individual
  #9  
Antiguo 08-02-2021
Avatar de juanelo
juanelo juanelo is offline
Miembro
 
Registrado: sep 2007
Posts: 1.085
Reputación: 19
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 19:24:32.
Responder Con Cita