Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 26-05-2005
hot1974 hot1974 is offline
Miembro
 
Registrado: jun 2003
Ubicación: Mexico D.F.
Posts: 31
Poder: 0
hot1974 Va por buen camino
Talking Importación de Contactos desde outlook

Hola a todos los foreros, gracias por dedicarle un espacio a estas lineas,
Tengo la siguiente necesidad, espero alguno de ustedes me pueda ayudar, necesito realizar un importador de la base de datos de contactos de outlook, nada mas que no tengo ni la menor idea por donde empezar, quisiera si me podrian ayudar con que tipo de archivo es, como lo leo que componentes debo de usar si es necesario usar los de la paleta de server y como se utilizan.

Gracias mil a todos.
Responder Con Cita
  #2  
Antiguo 26-05-2005
Avatar de marcoszorrilla
marcoszorrilla marcoszorrilla is offline
Capo
 
Registrado: may 2003
Ubicación: Cantabria - España
Posts: 11.221
Poder: 10
marcoszorrilla Va por buen camino
He encontrado esto en Torrys, no he hecho ninguna prueba, si te sirve y funciona nos lo comunicas.

Código Delphi [-]
 unit ExtractEmailsFunc;
 
 interface
 
 uses
   Windows, SysUtils;
 
 procedure CheckEMail(FilePath: string);
 
 implementation
 
 var
   BufferSize: Integer;
 
 function VerifyFile(strFileName: string): Integer;
 var
   intErro: Integer;
   tsrFile: TSearchRec;
 begin
   intErro := FindFirst(strFileName, FaAnyFile, tsrFile);
   if intErro = 0 then Result := tsrFile.Size 
   else 
     Result := -1;
   FindClose(tsrFile);
 end;
 
 procedure CheckEMail(FilePath: string);
 var
   I: Integer;
   hFile: Integer;
   Buffer: PChar;
   StrEmail: string;
 begin
   hFile := FileOpen(FilePath, fmOpenRead);
   try
     if hFile = 0 then Exit;
     GetMem(Buffer, bufferSize + 1);
     ZeroMemory(Buffer, BufferSize + 1);
     try
       FileRead(hFile, Buffer^, BufferSize);
       I := 0;
       while I <= BufferSize - 1 do 
       begin
         StrEmail := '';
         if Buffer[i] = '<' then 
         begin
           Inc(I);
           while (Buffer[i] <> '@') and (I <= BufferSize) do 
           begin
             if (Buffer[i] = CHR(45)) or (Buffer[i] = CHR(46)) or
               (Buffer[i] = CHR(90)) or ((Buffer[i] > CHR(49)) and (Buffer[i] <= CHR(57)))
               or ((Buffer[i] >= CHR(65)) and (Buffer[i] <= CHR(90))) or
               ((Buffer[i] >= CHR(97)) and (Buffer[i] <= CHR(122))) then 
             begin
               StrEmail := StrEmail + Buffer[i];
             end 
             else 
             begin
               StrEmail := '';
               Break;
             end;
             Inc(I);
           end;
           if StrEmail <> '' then 
           begin
             StrEmail := StrEmail + '@';
             Inc(I);
             while (Buffer[i] <> '.') and (I <= BufferSize) do 
             begin
               if (Buffer[i] = CHR(45)) or (Buffer[i] = CHR(46)) or
                 (Buffer[i] = CHR(90)) or ((Buffer[i] >= CHR(49)) and (Buffer[i] <= CHR(57)))
                 or ((Buffer[i] >= CHR(65)) and (Buffer[i] <= CHR(90))) or
                 ((Buffer[i] >= CHR(97)) and (Buffer[i] <= CHR(122))) then 
               begin
                 StrEmail := StrEmail + Buffer[i];
               end 
               else 
               begin
                 StrEmail := '';
                 Break;
               end;
               Inc(I);
             end;
             if StrEmail <> '' then 
             begin
               StrEmail := StrEmail + '.';
               Inc(i);
               while (Buffer[i] <> '>') and (I <= BufferSize) do 
               begin
                 if (Buffer[i] = CHR(45)) or (Buffer[i] = CHR(46)) or
                   (Buffer[i] = CHR(90)) or ((Buffer[i] >= CHR(49)) and (Buffer[i] <= CHR(57)))
                   or ((Buffer[i] >= CHR(65)) and (Buffer[i] <= CHR(90))) or
                   ((Buffer[i] >= CHR(97)) and (Buffer[i] <= CHR(122))) then 
                 begin
                   StrEmail := StrEmail + Buffer[i];
                 end 
                 else 
                 begin
                   StrEmail := '';
                   Break;
                 end;
                 Inc(I);
               end;
               if StrEmail <> '' then 
               begin
                 WriteLn(StrEmail);
                 Inc(I);
               end;
             end;
           end;
         end 
         else 
           Inc(I);
       end;
     finally
       FreeMem(Buffer);
     end;
   finally
     FileClose(hFile);
   end;
 end;
 
 begin
   BufferSize := VerifyFile(ParamStr(1));
   if BufferSize <= 0 then Exit;
   CheckEMail(ParamStr(1));
 end.

Un Saludo.
__________________
Guía de Estilo de los Foros
Cita:
- Ça c'est la caisse. Le mouton que tu veux est dedans.
Responder Con Cita
  #3  
Antiguo 26-05-2005
hot1974 hot1974 is offline
Miembro
 
Registrado: jun 2003
Ubicación: Mexico D.F.
Posts: 31
Poder: 0
hot1974 Va por buen camino
gracias

Gracias por tu respuesta marcos pero creo que no es lo que necesito ya que esta función extrae los correos electronicos, no la lista de contactos, gracias y seguimos buscando, espero mas ayuda.
Responder Con Cita
  #4  
Antiguo 27-05-2005
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
desde el outlook puedes hacer una exportación, esto te crea un archivo simple de texto con los datos separados por 'punto y coma', luego haces una sencilla importación leyendo ese ficherito de texto.
Responder Con Cita
  #5  
Antiguo 27-05-2005
hot1974 hot1974 is offline
Miembro
 
Registrado: jun 2003
Ubicación: Mexico D.F.
Posts: 31
Poder: 0
hot1974 Va por buen camino
Hola

Gracias por tu sugerencia casimiro, de hecho asi lo he estado trabajando de forma temporal hasta no encontrar la solucion, pero como comento al inicio del post estoy desarrollando u software que tome los datos directamente de la lista de contactos del outlook de forma transparente sin que haga nada el usuario, gracias por las respuestas y seguimos buscando
Responder Con Cita
  #6  
Antiguo 29-05-2005
jcasassa jcasassa is offline
Miembro
 
Registrado: may 2003
Posts: 12
Poder: 0
jcasassa Va por buen camino
Acceder a la libreta de direcciones de OutLook

Hola!

Busca aquí es la web ajpdsoft .

Creo que te servirá.

Joan
Responder Con Cita
  #7  
Antiguo 05-06-2005
hot1974 hot1974 is offline
Miembro
 
Registrado: jun 2003
Ubicación: Mexico D.F.
Posts: 31
Poder: 0
hot1974 Va por buen camino
Gracias mil

Perfecto joan me funciono a las mil maravillas mil gracias .
Saludos
Alejandro
Responder Con Cita
  #8  
Antiguo 09-06-2005
hot1974 hot1974 is offline
Miembro
 
Registrado: jun 2003
Ubicación: Mexico D.F.
Posts: 31
Poder: 0
hot1974 Va por buen camino
Respuesta

Este es el codigo que use espero les sirva

private
{ Private declarations }
public
{ Public declarations }
end;

var
FrmImporta: TFrmImporta;
linea : string;
carpetasOutlook : TStringList;

const
carContactos = $0000000A; //Contactos

implementation

{$R *.dfm}
procedure cargarCarpeta(Folder: OleVariant);
var
i : Integer;
begin
for i := 1 to Folder.Count do
begin
carpetasOutlook.Add(Folder.Item[i].Name);
cargarCarpeta(Folder.Item[i].Folders);
end;
end;

procedure TFrmImporta.Button1Click(Sender: TObject);
var
MsOutlook, MapiName, MisContactos : variant;
num,dato,y : integer;
contactosTemp : TStringList;
begin
lInfoContactos.Caption := 'Conectado a Outlook...';
lInfoContactos.Refresh;
// txtContactos.Lines.Clear;
try
MsOutlook := CreateOleObject('Outlook.Application');
except
on err : exception do
begin
lInfoContactos.Caption := '';
lInfoContactos.Refresh;
MessageDlg ('No se ha podido acceder a Outlook. Se ha producido el siguiente error: ' +
chr(13) + chr(13) + err.Message, mtError, [mbok], 0);
Exit;
end;
end;
try
MapiName := MsOutlook.GetNameSpace('MAPI');
If MsOutlook.name = 'Outlook' Then
begin
MapiName.Logoff;
MapiName.Logon('','');
bpContactos.Visible := true;
bpContactos.Min := 0;
dato:=MapiName.folders('Carpetas personales').folders(txtNombreContactos.text).items.count;
bpContactos.Max:=Dato-1;
for y := 1 to (dato-1) do
begin
bpContactos.Position := y;
bpContactos.Refresh;
lInfoContactos.Caption := 'Obteniendo contacto ' + inttostr(y) +
' de ' + inttostr(dato-1);
lInfoContactos.Refresh;
MisContactos := MapiName.folders('Carpetas personales').folders('Contactos').items(y);
try
linea := '';
Table1.Append;
Table1APaterno.Value := miscontactos.lastname;
Table1AMaterno.Value := miscontactos.middlename;
Table1Nombre.Value := MisContactos.firstname;
Table1Trabajo.Value := MisContactos.CompanyName;
//validacion de datos de cliente
if Table1Trabajo.Value<>'' then
begin
Table1Trabajo.Value;
Table3.IndexFieldNames:='descliente';
if not Table3.FindKey([Table1Trabajo.Value]) then
begin
Table3.IndexFieldNames:='cvecliente';
Table3.Last;
num:=Table3Cvecliente.AsInteger+1;
Table3.Append;
Table3Cvecliente.AsString:=inttostr(num);
Table3Descliente.Value:=MisContactos.CompanyName;;
Table3Dircliente.Value:=MisContactos.BusinessAddressStreet;
Table3Ciudad.Value :=MisContactos.BusinessAddressCity;
Table3Pais0.Value :=MisContactos.BusinessAddressCountry;
Table3CPcliente.Value :=MisContactos.BusinessAddressPostalCode;
Table3Estado1.Value :=MisContactos.BusinessAddressState;
end;
end;
Table1CalleYNumero.Value := miscontactos.HomeAddressStreet;
Table1Ciudad.Value := MisContactos.HomeAddressCity;
Table1Pais.Value := MisContactos.HomeAddressCountry;
Table1CodigoPostal.Value := MisContactos.HomeAddressPostalCode;
Table1Estado.Value := MisContactos.HomeAddressState;
Table1Contacto.Value := MisContactos.Title;
Table1Puesto.Value := MisContactos.department;
Table1.Post;
linea:=MisContactos.Email1Address;
if linea <> '' then
begin
Table2.Append;
Table2TipoDato.Value:='email';
Table2Dato.Value :=linea;
Table2.Post;
end;
linea:=MisContactos.BusinessTelephoneNumber;
if linea <> '' then
begin
Table2.Append;
Table2TipoDato.Value:='Telefono Oficina';
Table2Dato.Value :=linea;
Table2.Post;
end;
linea:=MisContactos.HomeTelephoneNumber;
if linea <> '' then
begin
Table2.Append;
Table2TipoDato.Value:='Telefono Casa';
Table2Dato.Value :=linea;
Table2.Post;
end;
linea:=MisContactos.MobileTelephoneNumber;
if linea <> '' then
begin
Table2.Append;
Table2TipoDato.Value:='Celular';
Table2Dato.Value :=linea;
Table2.Post;
end;
linea:=MisContactos.PersonalHomePage;
if linea <> '' then
begin
Table2.Append;
Table2TipoDato.Value:='Pagina Web';
Table2Dato.Value :=linea;
Table2.Post;
end;
except
end;
end;
ShowMessage('importacion Terminada');
close;

end
else
MessageDlg ('No se ha podido acceder a Outlook.', mtWarning, [mbok], 0);
except
on err : exception do
begin
lInfoContactos.Caption := '';
bpContactos.Visible := false;
MessageDlg ('No se ha podido acceder a Outlook. Se ha producido el siguiente error: ' +
chr(13) + chr(13) + err.Message, mtError, [mbok], 0);
MsOutlook := null;
end;
end;
MsOutlook := null;
end;

procedure TFrmImporta.FormCreate(Sender: TObject);
var
outlook : OLEVariant;
NameSpace : variant;
begin
Table1.Open;
Table2.Open;
Table3.Open;
try
//mostramos en el desplegable las carpetas de outlook
outlook := CreateOleObject('Outlook.Application');
NameSpace := outlook.GetNameSpace('MAPI');
carpetasOutlook := TStringList.Create;
cargarCarpeta(NameSpace.Folders);
txtNombreContactos.Clear;
txtNombreContactos.Items.AddStrings(carpetasOutlook);
//asignamos la carpeta de "contactos" por defecto
txtNombreContactos.Text := NameSpace.GetDefaultFolder(carContactos);
except
on err : exception do
begin
outlook := UnAssigned;
MessageDlg('No se ha podido acceder a Outlook con el perfil por defecto, compruebe los datos del perfil: ' +
chr(13) + chr(13) + err.message, mtInformation, [mbok], 0);
end;
end;
end;

end.

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


La franja horaria es GMT +2. Ahora son las 05:53:20.


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