Reading pdf in the IFS and writing as attachment to email using Qtmmsendmail not working

20 pts.
Email attachments
IBM iSeries
PDF attachments
I am trying to attach a pdf from our iseries system to an email as an attachment.  I am able to send the email and the attachement .  How ever the attachment(pdf) when I open it ... it is screwed up.  Contains only part of the pdf and has some lines through the body going down the page.  The pdf was out put of Eliteforms software ... has data with an overlay.  Only the overlay is showing up.    Does anyone have any code that I could compare mine with???      

Software/Hardware used:

Answer Wiki

Thanks. We'll let you know when a new response is added.

What I am doing is creating a temport pdf file first…then the necessary code to send an email
iswritten to the pdf. Then I need to attach a pdf that contains a customer invoice. After all of this
is in the temporary pdf then I use QTMMSENDMAIL to send the email. I receive an attachment in
an email. But it is only partially there.

Here is some of the code:
Thanks, Greg

* Create a temporary file in the IFS.
filename = %str(tmpnam(*omit));
c eval filelen = %len(%trimr(filename))
c eval %subst( filename : filelen +1 : 2 ) = x’0000′
c eval fileDesc = open(%trimr(filename)
c : o_creat + o_wronly + o_trunc +
c o_codePage
c : s_irwxu + s_iroth
c : asciiCodePage)
c eval returnInt = close( fileDesc )
c eval fileDesc = open(%trimr(filename)
c : o_textdata + o_rdwr)

* Build MIME header fields
c eval mSender = ‘Sender: ‘ + originator
c eval mDateTime = ‘Date: ‘
c eval mFrom = ‘From: ‘ +
c %trimr( originName ) + ‘ <‘ +
c %trimr( originator ) + ‘>’
c eval mMimeVer = ‘MIME-Version: 1.0’
c if addresseeName > *blanks
c eval mTo =
c ‘To: ‘ + %trimr( addresseeName ) +
c ‘ <‘ + %trimr( address ) + ‘>’
c else
c eval mTo = ‘To: ‘ + %trimr( address )
c endif
c if subject > *blanks
c eval mSubject = ‘Subject: ‘ + subject
c else
c eval mSubject = ‘Subject: ‘
c endif
c eval data = %trimr( mSender ) +
c eor +
c %trimr( mDateTime ) +
c eor +
c %trimr( mFrom) +
c eor +
c %trimr( mMimeVer) +
c eor +
c %trimr( mTo ) +
c eor +
c %trimr( mSubject ) +
c eor +
c ‘Content-Type: multipart/mixed; boundry=’ +
c ‘”‘ + %trimr( mBoundary ) + ‘”‘ +
c eor +
c eor +
c ‘This is a multi-part message in MIME ‘ +
c ‘format.’ + eor + eor +
c ‘–‘ + %trimr( mboundary ) +
c eor +
c ‘Content-Type: text/plain; charset=us-ascii’+
c eor +
c ‘Content-Transfer-Encoding: 7bit’ +
c eor + eor +
c %trimr( message ) +
c eor + eor + eor + eor +
c ‘–‘ + %trimr( mBoundary )

* Add attachment file(s) if requested
c eval nbrfiles = 1
c eval attachfile(1) = %trimr(attachfile(1)
c if nbrfiles > *zero
c and attachfile(1) <> ‘*NONE’
c exsr writefile
c do nbrfiles z
c clear savepos
c eval pos = %scan(‘/’:attachfile(z):1)
c dow pos > *zero
c eval savepos = pos
c eval pos = %scan(‘/’:attachfile(z):pos+1)
c enddo
c if savepos <> *zero
c eval attachname = %subst(attachfile(z):savepos+1)
c else
c eval attachname = attachfile(z)
c endif
c eval data = eor +
c ‘Content-Type: application/pdf’ +
c ‘-stream; name=”‘ +
c %trimr(attachname) + ‘”‘ +
c eor +
c ‘Content-Transfer-Encoding: 7bit’ +
c eor +
c ‘Content-Disposition: attachment; flename=”‘+
c %trimr(attachname) + ‘”‘ +
c eor + eor
c exsr writefile

* Open file
c eval attachfile(z) = %trimr(attachfile(z) + null
c eval attachdesc = open(%trimr(attachfile( z))
c : o_rdonly + o_textdata)

Discuss This Question: 2  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TomLiotta
    What did you use for the MIME encoding of the attachment? And what did you supply as the MIME headers? Tom
    125,585 pointsBadges:
  • TomLiotta
    You have this line for your Content-Transfer-Encoding of the .PDF attachment:
    c                             'Content-Transfer-Encoding: 7bit' +
    Have you verified that the attachment file meets the criteria? If it contains characters not in the 7-bit ASCII character set or it has lines longer than 1000 characters (including the required CRLF pair for each line) or it has NULLs anywhere in it, you'll have to encode it to some acceptable form and specify appropriate transfer encoding. Open the .PDF file with DSPF and look at it in hex. Or use DMP to dump it in hex and search through the spooled output for invalid hex values. Easiest test might be to use some basic client like Thunderbird to attach and send it to a test e-mail address. Then use Thunderbird to receive the e-mail and save the entire e-mail item into a file on a PC. Open that saved file in Notepad and look at how the MIME headers were built and what the successful attachment actually looked like. I would first suspect that you have characters in the attachment that cannot be sent through SMTP without proper MIME encoding before attaching it. SMTP only transfers 7-bit ASCII values, and only in a basic line format. If you attach anything, you have to ensure that it is in a format that SMTP handles and that the encoding type is one that is recognized by the client that will be receiving it. Base-64 encoding is one of the most widely recognized. Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: