Problem sending attachments via smtpmail.p

Posted by Admin on 15-Nov-2011 06:45

Hi All,

We are using smtpmail.p to send PDF documents from our progress application to our customers.
We have learned that some recipients allways recieve corrupted PDF files, while others receive the same file Ok (source file is identical).
We have tried supplying different mimetypes for the attachment, but this does not solve the problem.
So I expect that the problem is related to the encoding of the attachment.
Does anyone have any idea’s how to solve this?
We run smtpmail.p with the following input parameters:
    mailhub                       "mail.co-maker.local"
    EmailTo                       "s.kruiswijk@co-maker.nl"
    EmailFrom                    "s.kruiswijk@co-maker.nl"
    EmailCC/EmailBCC         ""
    Attachment descrlist       "00053663.pdf:type=application/octet-stream:filetype=binary"
    Attachment filelist          "\\co-maker.local\lofprogress\progres9\lofhd\1\DOC\factuur\2011\11\00053663.pdf"
    Subject                        ""
    Body                           "\\co-maker.local\lofprogress\progres9\lofhd\1\doc\doctmp\f53b4881b81e6c90e1117d0f1e5dcb34.html"
    MIMEHeader                 "type=text/html:charset=us-ascii:filetype=ascii"
    BodyType                     "file"
    Importance                  2 
    L_DoAUTH                    no
    C_AuthType                  ""
    C_User                        ""
    C_Password                  ""
Furthermore we have slightly altered smtpmail.p to do our base64 encoding.
We have replaced base64encode.p by calling the following function:
PROCEDURE OEb64encode:
  DEFINE INPUT PARAMETER ipFilenm AS CHARACTER NO-UNDO.
  DEFINE INPUT PARAMETER opFilenm AS CHARACTER NO-UNDO.
  DEFINE VARIABLE RetVal   AS CHARACTER NO-UNDO.
  DEFINE VARIABLE encdmptr AS MEMPTR    NO-UNDO.
  DEFINE VARIABLE encdlngc AS LONGCHAR  NO-UNDO.
  COPY-LOB FROM FILE ipFilenm TO encdmptr NO-ERROR.
  IF (NOT ERROR-STATUS:ERROR) THEN DO:
      ASSIGN encdlngc = BASE64-ENCODE(encdmptr) NO-ERROR.
  END.
  IF (NOT ERROR-STATUS:ERROR) THEN DO:
      COPY-LOB FROM encdlngc TO FILE opFilenm NO-ERROR.
  END.
  IF (ERROR-STATUS:ERROR) THEN DO:
      ASSIGN RetVal             = RETURN-VALUE
             SET-SIZE(encdmptr) = 0 NO-ERROR.
      RETURN ERROR RetVal.
  END.
  ASSIGN SET-SIZE(encdmptr) = 0 NO-ERROR.
END PROCEDURE.

All Replies

Posted by jankeir on 15-Nov-2011 07:12

We used to have this problem. I think it was caused by the fact that base64-encode does not split the output up in lines. Some mailservers choked on that. Splitting up the resulting output fixes that. I'm not entirely sure we changed it for this problem, but you might give it a shot. Below is our base64encode.p file.

/******************************************************************************/

/* OE10 way to base64encode attachments : use built-in base64-encode function */

/* Some mailserers demand the 76-character sized mail standard, so we split   */

/* the original long string into smaller pieces.                              */

/******************************************************************************/


DEFINE INPUT PARAMETER cInFileName AS CHAR NO-UNDO.

DEFINE INPUT PARAMETER cOutFileName AS CHAR NO-UNDO.


&SCOPED-DEFINE sdLength 76

DEFINE VARIABLE memFile       AS MEMPTR     NO-UNDO.

DEFINE VARIABLE cResult       AS LONGCHAR   NO-UNDO.

DEFINE VARIABLE cResultTempo  AS LONGCHAR   NO-UNDO.

DEFINE VARIABLE cResultEnter  AS LONGCHAR   NO-UNDO.

DEFINE VARIABLE crlf          AS CHARACTER  NO-UNDO.

DEFINE VARIABLE cFold         AS CHARACTER  NO-UNDO.

DEFINE VARIABLE iFileLength   AS INTEGER    NO-UNDO.

DEFINE VARIABLE iOffSet       AS INTEGER    NO-UNDO INIT 1.




ASSIGN FILE-INFO:FILE-NAME = cInFileName

  crlf = CHR(13) + CHR(10).


IF FILE-INFO:FULL-PATHNAME = ? THEN DO:

  OUTPUT TO VALUE(cInFileName).

  PUT UNFORMATTED "ERROR MESSAGE! File not found!" SKIP.

  OUTPUT CLOSE.

END.


IF FILE-INFO:FILE-SIZE > 12000000 THEN DO:

  OUTPUT TO VALUE(cInFileName).

  PUT UNFORMATTED "ERROR MESSAGE! File too large!" SKIP.

  OUTPUT CLOSE.

END.


COPY-LOB FROM FILE FILE-INFO:FULL-PATHNAME TO memFile.

cResult = BASE64-ENCODE (memFile).


ASSIGN cFold = "/usr/bin/fold".


IF SEARCH(cFold) = ? THEN

  ASSIGN cFold = SEARCH("fold.exe").


IF cFold = ? THEN DO: /* old system through pure progress */

  SET-SIZE(memFile) = 0.

  ASSIGN iFileLength = LENGTH(cResult).

  SET-SIZE(memFile) = iFileLength.

  COPY-LOB FROM cResult TO memFile.

 

  OS-DELETE cOutFileName.

  /* Apparently, our mailserver wants some chr(10) inbetween the base64'd files. Do some tweaking for this. */

  DO iOffSet = 1 TO iFileLength BY {&sdLength}:

    ASSIGN cResultEnter = cResultEnter +

      GET-STRING(memFile,iOffSet,MIN({&sdLength},(iFileLength - iOffSet + 1))) + crlf.

  END.

  COPY-LOB cResultEnter TO FILE cOutFileName.

  SET-SIZE(memFile) = 0.

END.

ELSE DO:

  COPY-LOB cResult TO FILE (cOutFileName + ".txt") .

  ASSIGN cFold = cFold + " -w 76 " + QUOTER(cOutFileName + ".txt") + " > " + QUOTER(cOutFileName).

  OS-COMMAND SILENT value(cFold).

  OS-DELETE value(cOutFileName + ".txt").

END.

Posted by Admin on 17-Nov-2011 07:10

Thanks! Splitting the attachment in

seperate lines solves the problem.

This thread is closed