2023 Oct 19 9:58 AM
Hello Experts,
I sent email contains attachment file type pdf but when I click on this file I can't display it. It displays pop up: We cannot open this file An error has occurred.
.... some code
DATA : gr_table type ref to cl_salv_table.
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = IT_FIRST ).
catch cx_salv_msg.
endtry.
"gr_table->display( ).
DATA : gv_xstring type xstring,
gv_xlen type int4,
gt_binary_table type solix_tab,
gr_request type ref to cl_bcs,
gv_body_text type bcsy_text,
gv_subject type so_obj_des,
gr_recipient type ref to if_recipient_bcs,
gr_document type ref to cl_document_bcs,
gv_size type so_obj_len.
* gv_sender_email TYPE string,
* gv_sender_name TYPE string.
try.
gv_xstring = gr_table->to_xml( if_salv_bs_xml=>c_type_xlsx ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = gv_xstring
* APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH = gv_xlen
TABLES
BINARY_TAB = gt_binary_table
.
gr_request = cl_bcs=>create_persistent( ).
append 'sample body text' to gv_body_text.
gv_subject = 'data19tes'.
gr_document = cl_document_bcs=>create_document(
i_type ='RAW'
i_text = gv_body_text
i_subject = gv_subject ).
gv_size = gv_xlen.
TRY.
CALL METHOD GR_DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = gv_subject && '.pdf'
i_attachment_size = gv_size
I_ATT_CONTENT_HEX = gt_binary_table[]
.
CATCH CX_DOCUMENT_BCS .
ENDTRY.
gr_request->set_document( gr_document ).
gr_recipient = cl_cam_address_bcs=>create_internet_address( 'recipentMail@gmail.com' ).
gr_request->add_recipient( gr_recipient ).
gr_request->send( ).
commit work.
MESSAGE 'E-mail sent' type 'S'.
catch cx_bcs.
MESSAGE 'E-mail sent' type 'A'.
endtry.
regards
2023 Oct 19 10:07 AM
have you tried modify your code bit by bit, such as removing the '.pdf' word from the attachment subject, or recheck your attachment size is correct (or not passing the attachment size at all)?
based on the information, I can only assume that it might be either two of what I mentioned above, or there is problem with the binary value for the pdf file itself, which you can make sure by downloading it into local pdf file.
2023 Oct 19 10:38 AM
thanks xiswanto for reply.
yes i removed '.pdf' word from the attachment subject . and comment i_attachment_size = gv_size . but same error. but when send excel file it's work . like that :
gr_document->add_attachment(
i_attachment_type ='EXT'
i_attachment_subject = gv_subject && '.xlsx'
i_attachment_size = gv_size
i_att_content_hex = gt_binary_table ).
2023 Oct 19 10:41 AM
Please use tags carefully. This has nothing to do with:
Also use the CODE button in the editor if your pasting code. (And use paste as text).
2023 Oct 19 11:04 AM
How about changing the imported xml code from this
gv_xstring = gr_table->to_xml( if_salv_bs_xml=>c_type_xlsx ).
into this
gv_xstring = gr_table->to_xml( if_salv_bs_xml=>c_type_pdf ).
2023 Oct 19 11:25 AM
If the PDF is ok, when saved into a local file, then the root cause for the problem most probably is a mail relay server somewhere between the sender and the receiver, which cannot handle 8-bit data. (Yes, even in the year 2023 there are still mail relay servers, which can handle only 7-bit US-ASCII data...!!)
I'm not sure, how the ABAP classes CL_BCS & CL_DOCUMENT_BCS work or whether they support the following, but in order to solve the problem, you would need to do the following (talking in terms of a general SMTP Client):
So what you need to do to fix this:
Any mail program like Microsoft Outlook etc. will automatically recognize the Content-Transfer-Encoding=base64 header, do the "reverse conversion" of the data (7-bit Base64 back to 8-bit binary) and display the PDF file correctly.
2023 Oct 19 2:06 PM
thanks ulrich.schmidt for a lot of information. I will try it .
2023 Oct 19 1:58 PM
2023 Oct 19 5:27 PM
trabelsioussa menu Actions > Edit to do what Matthew suggested.
NB: you MUST pass the RIGHT attachment length, no question about that. You have SAP demo programs which show the values for each parameter. I_ATTACHMENT_TYPE = 'EXT' is good ('PDF' is not valid here).