Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Problemas c/función para enviar mails con Outlook Express (https://www.clubdelphi.com/foros/showthread.php?t=25811)

Walterdf 04-10-2005 21:00:15

Problemas c/función para enviar mails con Outlook Express
 
Hola a todos.
Desarrollé una aplicación para preparar pedidos y enviarlos por email.
Para enviar x mail tomé un ejemplo de función (creo que la extraje de estos foros) que funciona bien salvo por el hecho de que una vez enviados los mensajes, todas las tablas, querys, etc pierden el DataBaseName. Suena muy extraño pero así es.
Trabajo con Delphi 6 y una simple base de datos en Paradox.
El código de la función es este:

Código Delphi [-]
 function SendMail(const Subject, Body, FileName, SenderName,
   SenderEMail, RecipientName, RecipientEMail: string): Integer;
 var
   Message: TMapiMessage;
   lpSender, lpRecipient: TMapiRecipDesc;
   FileAttach: TMapiFileDesc;
 
   SM: TFNMapiSendMail;
   MAPIModule: HModule;
 
 begin
   FillChar(Message, SizeOf(Message), 0);
   with Message do
   begin
     if (Subject <> '') then
       lpszSubject := PChar(Subject);
 
     if (Body <> '') then
       lpszNoteText := PChar(Body);
 
     if (SenderEmail <> '') then
     begin
       lpSender.ulRecipClass := MAPI_ORIG;
       if (SenderName = '') then
         lpSender.lpszName := PChar(SenderEMail)
       else
         lpSender.lpszName := PChar(SenderName);
         lpSender.lpszAddress := PChar(SenderEmail);
         lpSender.ulReserved := 0;
         lpSender.ulEIDSize := 0;
         lpSender.lpEntryID := nil;
         lpOriginator := @lpSender;
     end;
 
     if (RecipientEmail <> '') then
     begin
       lpRecipient.ulRecipClass := MAPI_TO;
       if (RecipientName = '') then
         lpRecipient.lpszName := PChar(RecipientEMail)
       else
         lpRecipient.lpszName := PChar(RecipientName);
         lpRecipient.lpszAddress := PChar(RecipientEmail);
         lpRecipient.ulReserved := 0;
         lpRecipient.ulEIDSize := 0;
         lpRecipient.lpEntryID := nil;
         nRecipCount := 1;
         lpRecips := @lpRecipient;
       end
       else
         lpRecips := nil;
 
     if (FileName = '') then
     begin
       nFileCount := 0;
       lpFiles := nil;
     end
     else
     begin
       FillChar(FileAttach, SizeOf(FileAttach), 0);
       FileAttach.nPosition := Cardinal($FFFFFFFF);
       FileAttach.lpszPathName := PChar(FileName);
 
       nFileCount := 1;
       lpFiles := @FileAttach;
     end;
   end;
 
   MAPIModule := LoadLibrary(PChar(MAPIDLL));
   if MAPIModule = 0 then
     Result := -1
   else
     try
       @SM := GetProcAddress(MAPIModule, 'MAPISendMail');
       if @SM <> nil then
       begin
         Result := SM(0, Application.Handle, Message, MAPI_DIALOG or MAPI_LOGON_UI, 0);
       end
       else
         Result := 1;
     finally
       FreeLibrary(MAPIModule);
     end;
 
   if Result <> 0 then
     MessageDlg('Error sending mail (' + IntToStr(Result) + ').', mtError, [mbOK], 0);
 end;
La llamada a la función la hago de la siguiente manera:

Código Delphi [-]
 SendMail('Pedidos', 'Envío pedidos para procesar', 'C:\Pedidos\pedidoX.pdf','',
   'origen@mail.com','','destino@mail.com' );
Espero puedan darme una mano.
Saludos y gracias de antemano.

Walter


La franja horaria es GMT +2. Ahora son las 05:01:31.

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