‎2008 Jul 19 3:00 PM
Hi, I need to send an email with an attachment in CSV format.
I have a comma delimited file (290 characters). I am using a method ( cl_hrrcf_services_mail->send_web_mail), but when I send the mail the attachment is empty.
I know a lot of developers use function module
'SO_NEW_DOCUMENT_ATT_SEND_API1'.
Has anybody use method method cl_hrrcf_services_mail to do this? Any ideas on how I can do this will be appreciated.
Thanks
Margariet
I
‎2008 Jul 19 3:16 PM
Hi,
Check this sample code: It calls a smartforms, generates a PDF and sends as attachment to external mailbox.
REPORT ytest_email.
* This example shows how to send
* - a simple text provided in an internal table of text lines
* - to some internet email address.
*
* All activities done via facade CL_BCS!
INCLUDE rlb_invoice_data_declare.
DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text.
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: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
START-OF-SELECTION.
PERFORM main.
*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
FORM main.
DATA: ls_bil_invoice TYPE lbbil_invoice.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: ls_addr_key LIKE addr_key.
DATA: ls_dlv-land LIKE vbrk-land1.
DATA: ls_job_info TYPE ssfcrescl.
DATA: I_CUST TYPE SCUSTOM.
DATA: I_BOOK TYPE TY_BOOKINGS,
I_CONN TYPE TY_CONNECTIONS.
DATA: W_I_SIZE TYPE I,
I_DOCS TYPE TABLE OF DOCS,
I_LINES TYPE TABLE OF TLINE.
DATA: I_OTF TYPE TSFOTF.
DATA: I_BIN TYPE SOLIX_TAB.
data: gd_buffer type string,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.
.
DATA: WA_LINES LIKE LINE OF I_LINES,
WA_PDF LIKE LINE OF I_BIN.
DATA: PDF_CONTENT TYPE SOLIX_TAB.
DATA: LP_PDF_SIZE TYPE SO_OBJ_LEN.
data: w_xstr type xstring,
w_len type i.
TRY.
* SF_EXAMPLE_01
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING formname = 'SF_EXAMPLE_01'
* variant = ' '
* direct_call = ' '
IMPORTING fm_name = lf_fm_name
EXCEPTIONS no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* error handling
ENDIF.
ls_control_param-getotf = 'X'.
ls_control_param-NO_DIALOG = 'X'.
* call smartform invoice
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
* mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = space
CUSTOMER = I_CUST
BOOKINGS = I_BOOK
CONNECTIONS = I_CONN
is_repeat = repeat
importing job_output_info = ls_job_info
* document_output_info =
* job_output_options =
EXCEPTIONS formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc = 0.
I_OTF = LS_JOB_INFO-OTFDATA[].
endif.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
* EXPORTING
* USE_OTF_MC_CMD = 'X'
* ARCHIVE_INDEX =
IMPORTING
BIN_FILESIZE = w_i_size
TABLES
OTF = I_OTF
DOCTAB_ARCHIVE = I_docs
LINES = I_LINES
* EXCEPTIONS
* ERR_CONV_NOT_POSSIBLE = 1
* ERR_OTF_MC_NOENDMARKER = 2
* OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Transfer the 132-long strings to 255-long strings
LOOP AT i_lines into wa_lines.
TRANSLATE wa_lines USING '~'.
CONCATENATE gd_buffer wa_lines INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~'.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = w_i_size
FIRST_LINE = 0
LAST_LINE = 0
IMPORTING
BUFFER = w_xstr
TABLES
BINARY_TAB = it_mess_att
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
PDF_CONTENT = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX( IP_XSTRING = w_xstr ).
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* create document from internal table with text
* APPEND 'Hello world!' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_TEXT = TEXT
i_length = '21'
i_subject = 'FORM TEST' ).
**add attachment to document
CALL METHOD document->add_attachment
EXPORTING i_attachment_type = 'PDF'
i_attachment_subject = 'MY ORDER CONFIRMATION'
* i_attachment_size = W_len
i_att_content_hex = pdf_content .
*
*
* add document to send request
CALL METHOD send_request->set_document( document ).
*
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
*
* sender = cl_sapuser_bcs=>create( sy-uname ).
* CALL METHOD send_request->set_sender
* EXPORTING
* i_sender = sender.
*
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address(
'give email address here' ).
*
* add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
*
*
recipient = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
*
*
*
* ---------- send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IF sent_to_all = 'X'.
WRITE text-003.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
WRITE: text-001.
WRITE: text-002, bcs_exception->error_type.
EXIT.
ENDTRY.
ENDFORM. "main
‎2008 Jul 25 11:11 AM
Hi
When I open the attachment all my data is in one line and the format is not correct.
My internal table is comma delimited and 290 characters.
Can somebody please help? I am using function module FUNCTION 'SO_DOCUMENT_SEND_API1' to send the mail to a Notes email address.
Thanks
Margariet
‎2008 Jul 25 11:18 AM
You must use FM as below
SO_NEW_DOCUMENT_ATT_SEND_API1.
Using se37 go into function module. Read its Documenation. You will find your solution.
regards
rajesh