In that document I am presenting a way on how to use the mail package in graphical mapping to send email with binary attachment (pdf).
In my scenario I have an incoming RFC call containing pdf lines which are base64 encoded. These lines are concatenated into one pdf document which is sent out as email attachment. The email has also a normal body part.
My first attempt was to use multipart/mixed content type and to create the mail package content in an udf taking care of the inline email body and the pdf attachment separated by boundaries. The problem was that the pdf attachment was base64 encoded in the email thus invalid. Decoding the pdf in the udf is not an option as the mail package content field is of string type (as it contains also the body text). So this approach works only for non binary attachments.
Next I tried to create the attachment in the global container and that did the trick. I am showing now that solution focusing only on the key objects which are the message mapping and the receiver channel.
In the source message we have DIJNET_NAM used for the file name, EMAIL_ADDRESS and DIJNET_TAB containing the pdf lines in BASE64.
We might have different type of lines but we are interested in pdf lines only (TYPE=’P’).
In the target message I deactivated the irrelevant fields.
Content_Type is set to text/html; charset=ISO-8859-2 because I am sending the email with html body.
Content_Disposition is set to inline because I want to display the html content in the email body (and not as attachment).
Content is created by the udf CreateContent.
The udf is taking rows (pdf lines), row types (for filtering on ‘P’) and filename as argument. We execute it on the whole queue as we need all the pdf lines to create the attachment.
We create the attachment as message attachment in the global container so we can use the Keep attachment flag in the mail receiver channel.
We also need to decode the pdf lines because we need the original binary content to get a valid pdf.
I am not using error handling (try/catch) to keep the tutorial as short as possible.