Ver Mensaje Individual
  #4  
Antiguo 09-05-2016
Avatar de juanelo
juanelo juanelo is offline
Miembro
 
Registrado: sep 2007
Posts: 1.083
Reputación: 18
juanelo Va por buen camino
Que tal Angel,
Te mando una funcion de como lo hago (solo que uso Indy 9.014), espero te ayude.

Código Delphi [-]
bool __fastcall TFrmMail::EnviaMail()   // Manda en silencio
{
  int i=0,Intento=0;
  bool Que=true;
  AnsiString Archivo,Imagen,Temp;

  TIniFile *Ini;
  if(Admin)
  {
    Ini= new TIniFile( ModuloDeDatos->DirExe + "CorreoAdmin.ini");
    Host=Ini->ReadString("Correo","Host","mail.correo.com");
    Port=Ini->ReadInteger("Correo","Port",26);
    UserID=Ini->ReadString("Correo","UserID","juanelo@correo.com");
    Password=Ini->ReadString("Correo","Password","****");
    FromAddress=Ini->ReadString("Correo","FromAddress","juanelo@correo.com");
    FromName=Ini->ReadString("Correo","FromName","IDEA Sistemas");
    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;
  }  

  BodyLines = new TStringList();

  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(UsaSTARTTLS)
  {
    SSL->SSLOptions->Method = sslvTLSv1;
    SSL->PassThrough = true;
  }

  if(UsaSSL)
    SMTP->IOHandler=SSL;
  // 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);

  BodyIndyText = new TIdText(Mensaje->MessageParts,NULL);
  BodyIndyText->ContentType="text/plain";
  BodyIndyText->Body->Text="";
  if(Admin)
    BodyLines->Add(Body);
  else
  {
    Temp=EdtBody->Text;
    EdtBody->Text=EdtTextAdicional->Text + " 
" + EdtBody->Text; BodyLines->Add(EdtBody->Text); Body=EdtBody->Text; }
BodyIndyHtml = new TIdText(Mensaje->MessageParts,BodyLines); BodyIndyHtml->ContentType="text/html"; BodyIndyHtml->Body->Clear(); BodyIndyHtml->Body->Add(Body); 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++; } 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(FileExists(Attach1)) IndyAttach1 = new TIdAttachment( Mensaje->MessageParts, Attach1 ); if(FileExists(Attach2)) IndyAttach2 = new TIdAttachment( Mensaje->MessageParts, Attach2); // Conectamos con el servidor SMTP while(Intento < 2) { try { try { Application->ProcessMessages(); if(Barra != NULL) Barra->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; if(SMTP->Connected()) { Application->ProcessMessages(); if(UsaSTARTTLS) SMTP->Authenticate(); if(Barra != NULL) Barra->Panels->Items[0]->Text="Enviando correo ... "; SMTP->Send(Mensaje); Application->ProcessMessages(); if(Barra != NULL) Barra->Panels->Items[0]->Text="Desconectando ... "; SMTP->Disconnect(); Application->ProcessMessages(); if(Barra != NULL) Barra->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; Application->ProcessMessages(); Que=false; if(Barra != NULL) Barra->Panels->Items[0]->Text="Error en el envio"; 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!
Responder Con Cita