Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   Fast Repost 4 Email + PDF adjunto (https://www.clubdelphi.com/foros/showthread.php?t=62476)

ajgomezlopez 27-12-2008 22:43:40

Fast Repost 4 Email + PDF adjunto
 
Buenas tardes, después de mucho mirar por google y de leerme la documentación de fast reports 4, no encuentro solución a este problema:

procedure TFborrador2.BitBtn4Click(Sender: TObject);
var
qborrador:TfrxADOQuery;
texto,fecha,nombre,dni,datos:TfrxMemoView;
begin
//Cargamos el formulario
iborrador.LoadFromFile('informes/iborrador.fr3');

...

//Lo mandamos por correo electrónico
frxmailexport1.ShowDialog := False;
frxmailexport1.Address:='maildestino@gmail.com';
frxmailexport1.FromMail := 'loquesea@loquesea.com';
frxmailexport1.Subject := 'Ejemplo 1';
frxmailexport1.SmtpHost := 'smtp.loquesea.ext';
frxmailexport1.SmtpPort := 25;
frxmailexport1.Login := 'login@server.com';
frxmailexport1.Password := 'mipassworddelserver';
frxmailexport1.ExportFilter := frxpdfexport1;
iborrador.Export(frxmailexport1);
end;

Según muchos sitios esto debería funcionar. Ejem:

http://www.fast-report.com/en/forum/...856&#entry8856

pero a mi me lanza este error:

First chance exception at $7C812AEB. Exception class EFCreateError with message 'Cannot create file "C:\DOCUME~1\*******\CONFIG~1\Temp\informes\iborrador.pdf". El sistema no puede hallar la ruta especificada'. Process Gapartados.exe (3712)

Ni especificando lo siguiente en el código funciona:

frxpdfExport1.FileName := TEMP + inttostr(Uborrador.codcliente) + '.pdf';

¿Alguna idea?

Me veo en la obligación de daros las gracias por adelantado.
Muchas gracias :)

Kipow 28-12-2008 10:27:00

mmm no se se me hace que no te esta aceptando nombres de archivos diferentes al standard 8.3 proba con un nombre como "C:\REPORTE.PDF"

ajgomezlopez 28-12-2008 12:22:28

Gracias
 
Muchas gracias por la respuesta, voy a ver si asi funciona y ya te cuento :)

========================

Gracias por la respuesta, pero eso no funciona, a ver si alguien le hecha un vistazo y me puede contestar. Muchas gracias.

Neftali [Germán.Estévez] 28-12-2008 19:59:44

Prueba a utilizar un path completo al guardar el fichero en lugar de un path relativo. Aunque sólo sea para descartar que sea de eso. Prueba por ejemplo guardando en un lugar tipo:

c:\temp\

Y asegúrate de que ese directorio existe. Si eso funciona, sabes que el problema radica en el pathdonde guardas el fichero.

Apuesto a que el error va por ahí. ¿El directorio donde estás intentando guardar existe?

PepeLolo 29-12-2008 01:47:03

Cuando empeze con FastReport 4 una de las cosas que me di cuenta es que no se registraba el email en mi cuenta de correo de Outloock, por lo que al final decido usar el siguiente código:

Código Delphi [-]
            with listado do
            begin
              with SaveDialog do
              begin
                filename:= 'ficheropdf.pdf';
                DefaultExt := 'pdf';
                InitialDir := 'c:\aplicacion\Usuario\email';  // Directorio de donde se guarda el pdf
                Filter := 'Archivos PDF de Adobe (*.pdf)|*.pdf';
                if Execute then
                begin
                  PrepareReport;
                  ExportTo(self.PsfrPDFExport, FileName);
                  mail := TStringList.Create;
                  try
                    mail.values['subject'] := Asunto;
                    mail.values['attachment0'] := FileName;
                    sendMail(Application.Handle, mail);
                  finally
                    mail.Free;
                  end;
                end;
              end;
           end;

La función sendMail es la siguiente, necesita las uses (mapi y shellapi):
Código Delphi [-]
function SendMail(Handle: THandle; Mail: TStrings): Cardinal;
type
  TAttachAccessArray = array [0..0] of TMapiFileDesc;
  PAttachAccessArray = ^TAttachAccessArray;
var
  MapiMessage: TMapiMessage;
  Receip: TMapiRecipDesc;
  Attachments: PAttachAccessArray;
  AttachCount: Integer;
  i1: integer;
  FileName: string;
  dwRet: Cardinal;
  MAPI_Session: Cardinal;
  WndList: Pointer;
begin
  dwRet := MapiLogon(Handle,
    PChar(''),
    PChar(''),
    MAPI_LOGON_UI or MAPI_NEW_SESSION,
    0, @MAPI_Session);

  if (dwRet <> SUCCESS_SUCCESS) then
  begin
    MessageBox(Handle,
      PChar('Error mientras se enviaba el email'),
      PChar('Error'),
      MB_ICONERROR or MB_OK);
  end
  else
  begin
    FillChar(MapiMessage, SizeOf(MapiMessage), #0);
    Attachments := nil;
    FillChar(Receip, SizeOf(Receip), #0);

    if Mail.Values['to'] <> '' then
    begin
      Receip.ulReserved := 0;
      Receip.ulRecipClass := MAPI_TO;
      Receip.lpszName := StrNew(PChar(Mail.Values['to']));
      Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
      Receip.ulEIDSize := 0;
      MapiMessage.nRecipCount := 1;
      MapiMessage.lpRecips := @Receip;
    end;

    AttachCount := 0;

    for i1 := 0 to MaxInt do
    begin
      if Mail.Values['attachment' + IntToStr(i1)] = '' then
        break;
      Inc(AttachCount);
    end;

    if AttachCount > 0 then
    begin
      GetMem(Attachments, SizeOf(TMapiFileDesc) * AttachCount);

      for i1 := 0 to AttachCount - 1 do
      begin
        FileName := Mail.Values['attachment' + IntToStr(i1)];
        Attachments[i1].ulReserved := 0;
        Attachments[i1].flFlags := 0;
        Attachments[i1].nPosition := ULONG($FFFFFFFF);
        Attachments[i1].lpszPathName := StrNew(PChar(FileName));
        Attachments[i1].lpszFileName :=
          StrNew(PChar(ExtractFileName(FileName)));
        Attachments[i1].lpFileType := nil;
      end;
      MapiMessage.nFileCount := AttachCount;
      MapiMessage.lpFiles := @Attachments^;
    end;

    if Mail.Values['subject'] <> '' then
      MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
    if Mail.Values['body'] <> '' then
      MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

    WndList := DisableTaskWindows(0);
    try
    Result := MapiSendMail(MAPI_Session, Handle,
      MapiMessage, MAPI_DIALOG, 0);
    finally
      EnableTaskWindows( WndList );
    end;

    for i1 := 0 to AttachCount - 1 do
    begin
      StrDispose(Attachments[i1].lpszPathName);
      StrDispose(Attachments[i1].lpszFileName);
    end;

    if Assigned(MapiMessage.lpszSubject) then
      StrDispose(MapiMessage.lpszSubject);
    if Assigned(MapiMessage.lpszNoteText) then
      StrDispose(MapiMessage.lpszNoteText);
    if Assigned(Receip.lpszAddress) then
      StrDispose(Receip.lpszAddress);
    if Assigned(Receip.lpszName) then
      StrDispose(Receip.lpszName);
    MapiLogOff(MAPI_Session, Handle, 0, 0);
  end;
end;

un saludo.

ajgomezlopez 29-12-2008 20:22:24

Gracias.
 
Muchas gracias a los dos por la contestación.

Neftalí, la ruta existe ese no es el problema, voy a seguir a ver si doy con la tecla, de todas maneras consiguo crear un pdf en la ruta que quiera, pero despues no el frxMailExport no veo ninguna opción para hacer un atach de un fichero.

Pepelobo tu código lo usaré si no saco el error, muchas gracias a ti también por ayudarme. Pero me gustaría sacar el fallo de los reportes. Muchas gracias.

A ver si a alguien se le ocurre.


La franja horaria es GMT +2. Ahora son las 09:40:02.

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