Generally we get requirements to email Smartforms as PDF attachment
For this we will get the OTF data from Smartform function module,convert OTF to PDF ,
and finally to send the pdf as mail we will use SO_NEW_DOCUMENT_ATT_SEND_API1 function module
but in smart form function module it self there is an option to send the mail to the recipient list
the below code shows how to achieve this functionality
DATA: recipient TYPE swc_object, sender TYPE swc_object, control_parameters TYPE ssfctrlop, output_options TYPE ssfcompop. mail_rec_obj TYPE swotobjid, mail_app_obj TYPE swotobjid, mail_sen_obj TYPE swotobjid. output_options-tdtitle = 'SMARTFORMS TO MAIL'. " Title of the PDF file control_parameters-device = 'MAIL'. *Sender Details PERFORM mail_sender_object CHANGING mail_sen_obj. * Recipient Details PERFORM mail_recipient_object CHANGING mail_rec_obj. *Application Object PERFORM mail_appl_object CHANGING mail_app_obj. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = l_formname * VARIANT = ' ' * DIRECT_CALL = ' ' IMPORTING fm_name = l_func_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. CALL FUNCTION l_func_name EXPORTING * ARCHIVE_INDEX = * ARCHIVE_INDEX_TAB = * ARCHIVE_PARAMETERS = control_parameters = control_parameters mail_appl_obj = mail_app_obj mail_recipient = mail_rec_obj mail_sender = mail_sen_obj output_options = output_options user_settings = 'X' * IMPORTING * DOCUMENT_OUTPUT_INFO = * JOB_OUTPUT_INFO = * JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. COMMIT WORK.&---------------------------------------------------------------------* *& Form mail_recipient_object *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_G_MAIL_REC_OBJ text *----------------------------------------------------------------------* FORM mail_recipient_object CHANGING p_mail_rec_obj. CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF' EXPORTING * IP_COUNTRY = * IP_FAXNO = ip_mailaddr = charlie786@gmail.com' "g_mail type "SO_NAME. ip_type_id = 'U' " 'U' IMPORTING ep_recipient_id = p_mail_rec_obj * EP_ADDRESS = * ET_RECIPIENT = EXCEPTIONS invalid_recipient = 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. ENDFORM. " mail_recipient_object *&---------------------------------------------------------------------* *& Form mail_sender_object *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_G_MAIL_SEN_OBJ text *----------------------------------------------------------------------* FORM mail_sender_object CHANGING p_mail_sen_obj. CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF' EXPORTING ip_sender = sy-uname IMPORTING ep_sender_id = p_mail_sen_obj EXCEPTIONS invalid_sender = 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. ENDFORM. " mail_sender_object *&---------------------------------------------------------------------* *& Form mail_appl_object *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_G_MAIL_APP_OBJ text *----------------------------------------------------------------------* FORM mail_appl_object CHANGING p_mail_app_obj. TYPES: BEGIN OF ty_sofmfol_key, foldertype LIKE sofm-foltp, folderyear LIKE sofm-folyr, foldernumber LIKE sofm-folno, type LIKE sofm-doctp, year LIKE sofm-docyr, number LIKE sofm-docno, forwarder LIKE soub-usrnam, END OF ty_sofmfol_key. DATA : sofmfol_key TYPE ty_sofmfol_key, folder TYPE swc_object, bor_key LIKE swotobjid-objkey. DATA l_sapnam TYPE soud. SELECT * FROM soud INTO l_sapnam WHERE sapnam EQ sy-uname AND deleted = ' '. ENDSELECT. IF sy-subrc NE 0. CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT' EXPORTING sapname = sy-uname EXCEPTIONS no_insert = 1 sap_name_exist = 2 x_error = 3 OTHERS = 4. IF sy-subrc NE 0. CLEAR l_sapnam. ELSE. SELECT * FROM soud INTO l_sapnam WHERE sapnam LIKE sy-uname AND deleted = ' '. ENDSELECT. ENDIF. ENDIF. CLEAR sofmfol_key. sofmfol_key-type = 'FOL'. sofmfol_key-year = l_sapnam-inbyr. sofmfol_key-number = l_sapnam-inbno. bor_key = sofmfol_key. IF NOT bor_key IS INITIAL. swc_create_object folder 'SOFMFOL' bor_key. IF sy-subrc = 0. swc_object_to_persistent folder p_mail_app_obj. IF sy-subrc NE 0. CLEAR p_mail_app_obj. ENDIF. ENDIF. ELSE. CLEAR p_mail_app_obj. ENDIF. ENDFORM. " mail_appl_object
please provide you feedback and comments
Thanks
Pawan Akella