‎2007 Aug 12 12:57 PM
Hi,
I need to send PDF files as attachment to a mail using Classes.
Is there a way to do it ?
Thanks.
David
‎2007 Aug 12 7:06 PM
Hi,
I have develop this code to send multiple HTML attachments using CL_BCS class
Form f_send_html_mail.
data: send_request type ref to cl_bcs.
data: document type ref to cl_document_bcs.
data: sender type ref to cl_sapuser_bcs.
data: recipient type ref to if_recipient_bcs.
data: exception_info type ref to if_os_exception_info,
bcs_exception type ref to cx_document_bcs.
data i_attachment_size type sood-objlen.
data v_status type bcs_stml.
data v_request_status type bcs_rqst.
data : v_desc like sopcklsti1-obj_descr.
concatenate 'Doc-' pdocno into v_desc.
condense v_desc no-gaps.
submit yttcr0001 exporting list to memory
with p_docno = pdocno
and return.
call function 'LIST_FROM_MEMORY'
tables
listobject = report_list
exceptions
not_found = 1
others = 2.
call function 'WWW_HTML_FROM_LISTOBJECT'
exporting
template_name = 'WEBREPORTING_REPORT'
tables
html = report_html
listobject = report_list.
describe table objbin lines tab_lines.
v_lines = tab_lines + 1.
loop at report_html.
move report_html to it_attach1.
append it_attach1.
endloop.
send_request = cl_bcs=>create_persistent( ).
try.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_content[]
i_subject = subject ).
if not attach_name1 is initial.
call method document->add_attachment
exporting
i_attachment_type = attach_ext1
i_attachment_subject = attach_name1
i_att_content_text = it_attach1[].
endif.
"<<< if you want multiple attachment then use this
if not attach_name2 is initial.
call method document->add_attachment
exporting
i_attachment_type = attach_ext2
i_attachment_subject = attach_name2
i_att_content_text = it_attach2[].
endif.
call method send_request->set_document( document ).
sender = cl_sapuser_bcs=>create( sy-uname ).
call method send_request->set_sender
exporting
i_sender = sender.
loop at it_recipient.
translate it_recipient-smtp_addr to lower case.
recipient = cl_cam_address_bcs=>create_internet_address( it_recipient-smtp_addr ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
endloop.
move : 'E' to v_request_status.
v_status = v_request_status.
call method send_request->set_status_attributes
exporting
i_requested_status = v_request_status
i_status_mail = v_status.
call method send_request->send( ).
commit work.
catch cx_document_bcs into bcs_exception.
endtry.
endform.
and also check this link
/people/thomas.jung3/blog/2005/01/05/develop-a-web-service-that-sends-an-email--in-abap
aRs
‎2007 Aug 12 6:57 PM
Hi David,
Did you already check the IF_SWF_UTL_MAIL ?
Regards,
Attila
‎2007 Aug 12 7:06 PM
Hi,
I have develop this code to send multiple HTML attachments using CL_BCS class
Form f_send_html_mail.
data: send_request type ref to cl_bcs.
data: document type ref to cl_document_bcs.
data: sender type ref to cl_sapuser_bcs.
data: recipient type ref to if_recipient_bcs.
data: exception_info type ref to if_os_exception_info,
bcs_exception type ref to cx_document_bcs.
data i_attachment_size type sood-objlen.
data v_status type bcs_stml.
data v_request_status type bcs_rqst.
data : v_desc like sopcklsti1-obj_descr.
concatenate 'Doc-' pdocno into v_desc.
condense v_desc no-gaps.
submit yttcr0001 exporting list to memory
with p_docno = pdocno
and return.
call function 'LIST_FROM_MEMORY'
tables
listobject = report_list
exceptions
not_found = 1
others = 2.
call function 'WWW_HTML_FROM_LISTOBJECT'
exporting
template_name = 'WEBREPORTING_REPORT'
tables
html = report_html
listobject = report_list.
describe table objbin lines tab_lines.
v_lines = tab_lines + 1.
loop at report_html.
move report_html to it_attach1.
append it_attach1.
endloop.
send_request = cl_bcs=>create_persistent( ).
try.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_content[]
i_subject = subject ).
if not attach_name1 is initial.
call method document->add_attachment
exporting
i_attachment_type = attach_ext1
i_attachment_subject = attach_name1
i_att_content_text = it_attach1[].
endif.
"<<< if you want multiple attachment then use this
if not attach_name2 is initial.
call method document->add_attachment
exporting
i_attachment_type = attach_ext2
i_attachment_subject = attach_name2
i_att_content_text = it_attach2[].
endif.
call method send_request->set_document( document ).
sender = cl_sapuser_bcs=>create( sy-uname ).
call method send_request->set_sender
exporting
i_sender = sender.
loop at it_recipient.
translate it_recipient-smtp_addr to lower case.
recipient = cl_cam_address_bcs=>create_internet_address( it_recipient-smtp_addr ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
endloop.
move : 'E' to v_request_status.
v_status = v_request_status.
call method send_request->set_status_attributes
exporting
i_requested_status = v_request_status
i_status_mail = v_status.
call method send_request->send( ).
commit work.
catch cx_document_bcs into bcs_exception.
endtry.
endform.
and also check this link
/people/thomas.jung3/blog/2005/01/05/develop-a-web-service-that-sends-an-email--in-abap
aRs
‎2007 Aug 13 9:39 AM
Hi,
Just one question : How do you fill the it_attach1 ?
thanks.
Regards
‎2007 Aug 13 9:48 AM
Hi David
You can use BCS for this
Check these progs BCS_EXAMPLE_1, BCS_EXAMPLE_2, BCS_EXAMPLE_3, BCS_EXAMPLE_4, BCS_EXAMPLE_5, BCS_EXAMPLE_6 in your R/3
Reward points if useful
Cheers
~Arun
‎2007 Aug 14 10:46 AM
‎2007 Aug 13 9:49 AM
Hi David,
look via se38 for BCS_EXAMPLE_*.
There are very good examples.
Regards, Dieter
‎2007 Aug 13 10:29 AM
Hi,
How can I read the binary from file without using GUI_UPLOAD because I want to run the program in background ?
Thanks,
‎2007 Aug 13 4:37 PM
Hi,
I have created my it_attach1...5 attachment this way.
form f_append_object_bin tables pattach structure soli
using pdocno pctc pscc .
data : v_desc like sopcklsti1-obj_descr.
if not pdocno is initial.
concatenate 'TCC-' pdocno into v_desc.
condense v_desc no-gaps.
submit ytccr0001 exporting list to memory
with p_docno = pdocno
and return.
call function 'LIST_FROM_MEMORY'
tables
listobject = report_list
exceptions
not_found = 1
others = 2.
call function 'WWW_HTML_FROM_LISTOBJECT'
exporting
template_name = 'WEBREPORTING_REPORT'
tables
html = report_html
listobject = report_list.
describe table objbin lines tab_lines.
v_lines = tab_lines + 1.
loop at report_html.
move report_html to pattach.
append pattach.
endloop.
endif.
endform. " F_append_object_bin
May this one help you out.
aRs