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: 

Sending mails with binary attachments

Peter_Lintner
Participant
0 Kudos
231

Hi!

I've to implement a routine for sending an email with attachments.

These attachments can be PDF- or HTML-Files. Sometimes the last of the PDF-Attachments could not be opened when receiving the mail (it can't be open in the SOST as well).

My coding is:

loop at lt_doks.

select single * from toadv where ar_object eq lt_doks-ar_object.

call function 'ARCHIVOBJECT_GET_TABLE'

exporting

archiv_id = lt_doks-archiv_id

document_type = toadv-doc_type

archiv_doc_id = lt_doks-arc_doc_id

importing

length = l_length

tables

archivobject = l_image_tab

exceptions

error_archiv = 1

error_communicationtable = 2

error_kernel = 3

others = 4.

clear objpack.

perform convert_document tables l_image_tab

objbin

using tab_lines_new

i_pernr

i_reinr

l_subrc.

if l_subrc ne 0.

raise convert_error.

endif.

objpack-transf_bin = 'X'.

objpack-head_start = 3.

objpack-head_num = 0.

objpack-body_start = tab_lines + 1.

objpack-body_num = tab_lines_new.

objpack-doc_type = toadv-doc_type.

objpack-obj_name = 'Attachment'.

objpack-obj_descr = lt_doks-objecttext.

objpack-doc_size = tab_lines_new * 255."l_length.

append objpack.

tab_lines = tab_lines + tab_lines_new.

clear tab_lines_new.

endloop.

endif.

endif.

if not document_data-obj_descr is initial.

  • jetzt wird's ernst -> Mail versenden

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = document_data

put_in_outbox = ' '

commit_work = 'X'

tables

packing_list = objpack

contents_txt = daten

contents_bin = objbin

receivers = receivers

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.

endif.

form convert_document tables p_image_tab structure docs

p_objbin structure solisti1

using p_lines

p_pernr

p_reinr

p_subrc.

data: l_filename like filename-fileextern.

clear p_lines.

call function 'FILE_GET_NAME'

exporting

client = sy-mandt

logical_filename = 'Z_HRTV_CONVERT'

operating_system = sy-opsys

parameter_1 = p_pernr

parameter_2 = p_reinr

importing

file_name = l_filename

exceptions

file_not_found = 1

others = 2.

if sy-subrc ne 0.

p_subrc = sy-subrc.

exit.

endif.

  • Schreiben der Datei

open dataset l_filename for output in binary mode.

loop at p_image_tab.

transfer p_image_tab to l_filename.

endloop.

close dataset l_filename.

refresh p_image_tab.

clear p_image_tab.

  • Lesen der Datei

open dataset l_filename for input in binary mode.

do.

read dataset l_filename into p_objbin.

if sy-subrc <> 0.

if not p_objbin is initial.

append p_objbin.

clear p_objbin.

add 1 to p_lines.

endif.

exit.

endif.

append p_objbin.

clear p_objbin.

add 1 to p_lines.

enddo.

close dataset l_filename.

  • Löschen der Datei

delete dataset l_filename.

endform. " convert_document

Can anybody give me hint?

Thanks a lot!

Peter

2 REPLIES 2

former_member194669
Active Contributor
0 Kudos
85

Hi,

Whether your objpack-doc_type is coming correctly for the last PDF attachment?

Thanks

aRs

Peter_Lintner
Participant
0 Kudos
85

Hi!

I've solved the problem myself!

Thanks

Peter