Hi Gurus,
I am facing problem in excel file send via email. I am using CL_BCS for sending email.
I saved my data in Tab limited format and passed to the method.
The problem is when I open the file in email it says file is not in correct format,still do you want to open the file.
(I think its because it is tab limited file)
When I click on Yes it opens the file in excel and data is also correct. All other data in email is also going perfect.
But it should not give error on opening of file. Please suggest what can be done to avoid this.
I have some HTML format data also so main document type I am passing is HTM.
Follwing is the reference code.
"*************************************************************
*" Send Email
"*************************************************************
try.
*" Create persistent send request
move cl_bcs=>create_persistent( ) to w_send_request.
*" Create document from internal table with text
clear: w_cnt,
w_length.
describe table i_email_data lines w_cnt.
read table i_email_data into e_email_data
index w_cnt.
if sy-subrc eq 0.
*" Total size of Email Body
w_length = ( w_cnt - 1 ) * 255 + strlen( e_email_data ).
endif.
*" Create Email Body
move cl_document_bcs=>create_document(
i_type = c_htm
i_text = i_email_data[]
i_length = w_length
i_subject = w_us_subject )
to w_document.
try .
call method w_send_request->set_message_subject
exporting
ip_subject = w_email_subject.
catch cx_sy_dyn_call_illegal_method .
endtry.
*" Add document to send request
call method w_send_request->set_document( w_document ).
*" Add Attachment
if not i_excel_data[] is initial.
clear: w_cnt,
w_length.
describe table i_excel_data lines w_cnt.
read table i_email_data into e_email_data
index w_cnt.
if sy-subrc eq 0.
*" Total size of Email Body
w_length = ( w_cnt + 10 ) * 255.
endif.
call method w_document->add_attachment
exporting
i_attachment_type = c_xls (c_xls = 'XLS')
i_attachment_subject = c_attach_title (c_attach_title = 'TESTEXCE')
i_attachment_size = w_length
i_att_content_text = i_excel_data[]. (This is tab limited data)
endif.
*" Set sender
move cl_sapuser_bcs=>create( w_sender_id ) to w_sender.
call method w_send_request->set_sender
exporting
i_sender = w_sender.
loop at i_receivers assigning <fs_receivers>.
*" Add To recipient (e-mail address)
if <fs_receivers>-cc_flag ne c_x.
move <fs_receivers>-receiver to w_receiver_email_address.
*" Add recipient (e-mail address)
move cl_cam_address_bcs=>create_internet_address(
w_receiver_email_address )
to w_recipient.
*" Add recipient with its respective attributes to send request
call method w_send_request->add_recipient
exporting
i_recipient = w_recipient
i_express = c_x.
endif.
*" Add Cc recipient (e-mail address)
if <fs_receivers>-cc_flag eq c_x.
move <fs_receivers>-receiver to w_receiver_email_address.
move cl_cam_address_bcs=>create_internet_address(
w_receiver_email_address )
to w_recipient.
*" Add recipient with its respective attributes to send request
call method w_send_request->add_recipient
exporting
i_recipient = w_recipient
i_express = c_x
i_copy = c_x.
endif.
endloop.
**set sending immediately
call method w_send_request->set_send_immediately
exporting
i_send_immediately = c_x.
*" Send document
call method w_send_request->send(
exporting
i_with_error_screen = c_x
receiving
result = w_sent_to_all ).