Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

problem with pdf as email attachment

Former Member
0 Kudos

Hi All,

when i am opening the pdf file(email attachment), getting the error "file type not support or content conversion....."

the peice of code is as followed...

IF p_email = 'X'.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = mi_rqident (spool number)

TABLES

buffer = l_contents.

IF l_contents IS NOT INITIAL.

CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'

EXPORTING

ip_solitab = l_contents

IMPORTING

ep_solixtab = contents_hex.

  • Create the send request

TRY.

l_send_request = cl_bcs=>create_persistent( ).

  • Create the main document

l_doc = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = l_text

i_subject = p_sub ).

  • Add attachment to document

l_doc->add_attachment( i_attachment_type = 'PDF'

i_attachment_subject = p_doc

  • i_att_content_text = contents_text ).

i_att_content_hex = contents_hex ).

  • Add document to send request

l_send_request->set_document( l_doc ).

  • Add recipients to send request

l_recipient = cl_cam_address_bcs=>create_internet_address(

p_email1-low ).

l_send_request->add_recipient( i_recipient = l_recipient ).

  • Send email

l_sent_all = l_send_request->send( ).

and other way also i tried, please let me know the solution.

thanks in advance

3 REPLIES 3

Former Member
0 Kudos

Hi

Can you paste the complete code.

Regards

Former Member
0 Kudos

HI,

Proceed as below:

1. Using the spool number call function: CONVERT_ABAPSPOOLJOB_2_PDF

2. Now pass these contents when attaching the file.

Check this thread [https://forums.sdn.sap.com/click.jspa?searchID=17595844&messageID=4827265]

Regards

Eswar

Former Member
0 Kudos

try this code ..

  • For mailing(converting data to char 255)

IF ch2 EQ 'X'.

DATA sub TYPE string.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = i_tline

t_target_tab = so_ali[]

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

  • Mail Contents

refresh objtxt[].

objtxt = space.

APPEND objtxt.

objtxt = 'Dear Sir/Madam,'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

CLEAR : sub.

CONCATENATE 'Sub: Dispatch Details - Invoice Number :' invno '.' INTO sub SEPARATED BY space.

objtxt = sub.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = 'We have dispatched the subject consignment from our factory, and'.

APPEND objtxt.

objtxt = 'enclose the Invoice(pdf file) for your kind reference.'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = 'Note: Please cover insurance on all risks in case INCO TERMS as "EXW, FCA, FOB, CFR"'.

APPEND objtxt.

objtxt = 'in the subject consignment.'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = 'For Delivery Management - International,'.

APPEND objtxt.

objtxt = 'Pricol Limited,'.

APPEND objtxt.

objtxt = 'Coimbatore. India.'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

  • Determining the Email Ids of Mail Receivers

PERFORM fetch_mailids.

objtxt = 'Copy to :'.

APPEND objtxt.

LOOP AT reclist.

objtxt = reclist-receiver.

APPEND objtxt.

ENDLOOP.

objtxt = space.

APPEND objtxt.

objtxt = '<This is system generated message>.'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

  • Mail Body of message over.

DESCRIBE TABLE objtxt[] LINES v_lines_txt.

CONCATENATE 'Inv.' invno INTO sub SEPARATED BY space.

doc_chng-obj_name = sub.

doc_chng-expiry_dat = sy-datum + 10.

  • Mail Subject

refresh objpack[].

CONCATENATE 'Pricol Dispatch - Invoice' invno '- Reg.' INTO sub SEPARATED BY space.

doc_chng-obj_descr = sub.

doc_chng-sensitivty = 'F'.

doc_chng-doc_size = v_lines_txt * 255.

objpack-transf_bin = ' '.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = v_lines_txt.

objpack-doc_type = 'RAW'.

APPEND objpack.

*PDF Attachment

DESCRIBE TABLE so_ali[] LINES lineno.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-doc_size = lineno * 255 .

objpack-body_num = lineno.

objpack-doc_type = 'PDF'.

objpack-obj_name = 'INVOICE'.

objpack-obj_descr = 'Invoice'.

objpack-obj_langu = 'E'.

APPEND objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

contents_txt = objtxt[]

contents_bin = so_ali[]

*contents_hex = so_ali[]

receivers = reclist[]

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc = 0.

PERFORM mail.

MESSAGE 'Mail sent successfully' TYPE 'S'.

*SUBMIT RSCONN01 WITH MODE = MODE.

ENDIF.

ENDIF.

ENDLOOP.