04-18-2013 4:37 PM
Hi Experts,
I'm using Function module CONVERT_OTF_AND_MAIL
this will covert sapscript into a pdf file, attach it to a mail and send.
Now i want to add BODY to the mail.
Please help me how can i add body to the mail, when i'm using CONVERT_OTF_AND_MAIL function module.
04-19-2013 5:42 AM
Hi Mukesh,
I don't think you can add email body when using CONVERT_OTF_AND_MAIL to send out mails. The purpose of this Function Module is only to convert the otf data, attach it to a mail and send to the recipients. You may have to look for alternatives which doesn't use this particular FM.
Hope this helps,
~Athreya
04-19-2013 9:59 AM
Hi,
I think you have to try build mail by yourself, instead of using CONVERT_OTF_AND_MAIL
Here is the example :
* Mail data
DATA : send_request TYPE REF TO cl_bcs.
DATA : document TYPE REF TO cl_document_bcs,
lv_lines TYPE i,
lv_size TYPE sood-objlen.
DATA : lt_text TYPE soli_tab,
ls_text TYPE soli,
lv_subject TYPE so_obj_des.
DATA : sent_to_all TYPE os_boolean.
CONSTANTS : c_raw TYPE so_obj_tp VALUE 'RAW'.
* PDF & OTF data
DATA : lt_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
lt_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
ls_pdf TYPE tline,
lv_bin_filesize TYPE i,
lt_data TYPE solix_tab,
ls_data TYPE solix,
lv_pdfx TYPE xstring.
DATA : lv_max TYPE i,
lv_next TYPE i,
current TYPE i,
line TYPE i.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_pdfx
TABLES
otf = lt_otf
lines = lt_pdf.
IF sy-subrc EQ 0.
lv_max = lv_bin_filesize.
current = 0.
DO.
lv_next = lv_max - current.
IF lv_next > 255.
line = 255.
ELSE.
line = lv_next.
ENDIF.
ls_data-line = lv_pdfx+current(line).
APPEND ls_data
TO lt_data.
CLEAR : ls_data.
current = current + line.
IF current = lv_max.
EXIT.
ENDIF.
ENDDO.
ELSE.
EXIT.
ENDIF.
TRY.
* ---------- create persistent send request ----------------------
send_request = cl_bcs=>create_persistent( ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = cl_cam_address_bcs=>create_internet_address( 'mail@example.com' ).
* ------------------------------------------------------------------
* * exception handling
* ------------------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* ------------------------------------------------------------------
CATCH cx_bcs.
EXIT.
ENDTRY.
lv_subject = 'Test Mail'.
CONCATENATE cl_abap_char_utilities=>newline
'This is mail BODY'
cl_abap_char_utilities=>newline
'We can add as many line as possible'
INTO ls_text-line
SEPARATED BY space.
APPEND ls_text
TO lt_text.
document = cl_document_bcs=>create_document( i_type = c_raw
i_subject = lv_subject
i_text = lt_text ).
lv_size = lines( lt_data ) * 255.
document->add_attachment( i_attachment_type = 'PDF'
i_attachment_subject = 'Attachment' " name of attachment
i_attachment_size = lv_size
i_att_content_hex = lt_data )."PDF data
document->set_importance( '1' ).
document->set_sensitivity( '1' ).
* add document to send request
send_request->set_document( document ).
* add recipient to send request
TRY .
send_request->add_recipient( i_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = 'mail@example.com' ) ).
CATCH cx_address_bcs.
EXIT.
ENDTRY.
TRY .
CALL METHOD send_request->send
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all.
CATCH cx_send_req_bcs.
RAISE send_error.
ENDTRY.
IF sent_to_all EQ 'X'.
* ---------- explicit 'commit work' is mandatory! ----------------
WAIT UP TO 2 SECONDS.
COMMIT WORK.
ELSE.
EXIT.
ENDIF.
I hope this will help.
04-19-2013 11:24 AM
Hi Mukesh,
CONVERT_OTF_AND_MAIL is used only to send emails with Attachments without Body.
Instead use CONVERT_OTF function module for converting your Scripts.
And use SO_NEW_DOCUMENT_ATT_SEND_API1 function module for sending mails with attachment and body.
Regards,
AyyamPerumal