cancel
Showing results for 
Search instead for 
Did you mean: 

Standard form for mailing?

Former Member
0 Kudos
121

Hi,

I need to send an error log(80 character with multiple lines) to user's internet mail id using SMARFORM. I like to know whether any Standard smartform i can use for this?

Thanks

Sa_R

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Gabriel,

Thanks for your reply.

In your second thread , the code you pasted is not readable, can you please repaste the same.

Thanks

Sa_R

Former Member
0 Kudos

Hey,

Post your email adress, I dont know why it isnt readable.

Bye

Gabriel

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

My email id arsmony@rediffmail.com.

Points awarded .

Thanks

Sa_R

Former Member
0 Kudos

Hi,

Check this link.

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&

Regards

Aneesh.

Former Member
0 Kudos

Hello Again

you can do it also like this on smartforms:

Notice that you have to talk with your basis team in order to be able to send external mails.

REPORT ymail2.

DATA:

  • tablas

et_return TYPE bapiret2_tab,

receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE , "receivers

  • vriables

iv_smartform TYPE tdsfname,

send_partner TYPE bu_partner, "from address

mail_subject TYPE so_obj_des.

send_partner = 'gpulido'.

MAIL_SUBJECT = 'TEST FORM MADE IN SMARTFORM'.

receivers-receiver = 'bgiraldo'.

receivers-rec_type = 'B'.

APPEND receivers.

receivers-receiver = 'gabe_pu@hotmail.com'.

receivers-rec_type = 'U'.

APPEND receivers.

receivers-receiver = 'gpulido'.

receivers-rec_type = 'B'.

APPEND receivers.

iv_smartform = 'YSEND_MAIL'.

PERFORM send_smartform_html_email

TABLES et_return receivers

USING iv_smartform send_partner mail_subject .

WRITE 'done?'.

&----


*& Form SEND_SMARTFORM_HTML_EMAIL

&----


  • RETREIVES CONTENT FROM SMARTFORM AND SENDS EMAIL TO THE RECEIVERS

----


  • -->ET_RETURN ERROR OR INFORMATIONAL MESSAGES

  • -->RECEIVERS EMAIL RECEPIENTS

  • -->FORM_NAME FORM NAME

  • -->MAIL_SUBJECT EMAIL SUBJECT

----


FORM send_smartform_html_email

TABLES

et_return TYPE bapiret2_tab

receivers STRUCTURE somlreci1 "receivers

USING

iv_smartform TYPE tdsfname

send_partner TYPE bu_partner "from address

mail_subject TYPE so_obj_des.

DATA: control_parameters TYPE ssfctrlop,

output_options TYPE ssfcompop,

document_output_info TYPE ssfcrespd,

job_output_info TYPE ssfcrescl,

job_output_options TYPE ssfcresop,

xsfparam_line TYPE ssfxsfp,

p_html TYPE trfresult,

p_graphics TYPE tsf_xsf_gr,

form_name TYPE rs38l_fnam. " generated function module name

DATA: wa_return TYPE bapiret2.

CONSTANTS: c_gr_dir TYPE tdtext VALUE 'MYGRAPHICS/'. "#EC NOTEXT

*SET SMARTFORM OUTPUT OPTIONS

output_options-xsfcmode = 'X'. "#EC NOTEXT

output_options-xsf = 'X'. "#EC NOTEXT

output_options-xsfoutmode = 'A'. "#EC NOTEXT

output_options-xsfformat = 'X'. "#EC NOTEXT

CLEAR output_options-xsfoutdev.

xsfparam_line-name = 'GRAPHICS'. "#EC NOTEXT

xsfparam_line-value = 'EXTRACT'. "#EC NOTEXT

APPEND xsfparam_line TO output_options-xsfpars.

xsfparam_line-name = 'GRAPHICS-DIRECTORY'. "#EC NOTEXT

xsfparam_line-value = c_gr_dir.

APPEND xsfparam_line TO output_options-xsfpars.

xsfparam_line-name = 'CONTENT-ID'. "#EC NOTEXT

xsfparam_line-value = 'ENABLE'. "#EC NOTEXT

APPEND xsfparam_line TO output_options-xsfpars.

  • SILENT MODE ON

output_options-tdimmed = space.

output_options-tdnewid = space.

control_parameters-no_dialog = 'X'. "#EC NOTEXT

  • Get the generated function name of the smartform

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' "#EC NOTEXT

EXPORTING

formname = iv_smartform

IMPORTING

fm_name = form_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • Error receiving the generated function module

CLEAR wa_return.

BREAK gpulido.

  • MESSAGE E005 WITH IV_SMARTFORM INTO WA_RETURN-MESSAGE. gpulido

WRITE /'ERROR 1'.

wa_return-type = 'E'. "#EC NOTEXT

INSERT wa_return INTO TABLE et_return.

EXIT.

ENDIF.

  • Get the smartform content

CALL FUNCTION form_name

EXPORTING

control_parameters = control_parameters

output_options = output_options

*pass other application specific parameters (eg order number, items ).

IMPORTING

document_output_info = document_output_info

job_output_info = job_output_info

job_output_options = job_output_options

EXCEPTIONS

formatting_error

=1

internal_error

=2

send_error

=3

user_canceled = 4.

IF sy-subrc <> 0.

  • FAILED TO GET CONTENT FROM SMARTFORM

CLEAR wa_return.

  • MESSAGE E012 WITH FORM_NAME SY-SUBRC INTO gpulido

WRITE /'FAILED TO GET CONTENT FROM SMARTFORM'.

*WA_RETURN-MESSAGE.

INSERT wa_return INTO TABLE et_return.

EXIT.

ENDIF.

p_html = job_output_info-xmloutput-trfresult.

p_graphics[] = job_output_info-xmloutput-xsfgr[].

  • send the extracted content all the recipients

PERFORM send_html_email

TABLES

et_return

receivers

USING

p_html

p_graphics[]

send_partner

mail_subject.

ENDFORM. "SEND_SMARTFORM_HTML_EMAIL

&----


*& Form SEND_HTML_EMAIL

&----


  • Send the email provided the content and other details

----


  • -->P_RETURN Error messages

  • -->P_RECEIVERS emailr recipients

  • -->P_HTML html text

  • -->P_GRAPHICS html graphics if any

  • -->P_SUBJECT subject of the email

----


FORM send_html_email

TABLES

p_return TYPE bapiret2_tab

p_receivers STRUCTURE somlreci1

USING p_html TYPE trfresult

p_graphics TYPE tsf_xsf_gr

send_partner TYPE bu_partner

p_subject TYPE so_obj_des.

DATA: l_graphic TYPE ssf_xsf_gr.

CONSTANTS: c_gr_dir TYPE tdtext VALUE 'MYGRAPHICS/'. "#EC NOTEXT

DATA: html_data TYPE trfresult,

graphics TYPE tsf_xsf_gr,

lv_sent_to_all TYPE boolean,

lv_send_address TYPE adr6-smtp_addr,

li_sender TYPE REF TO if_sender_bcs,

receiver TYPE somlreci1.

DATA: lo_bcs TYPE REF TO cl_bcs,

lo_doc_bcs TYPE REF TO cl_document_bcs,

lo_mime_helper TYPE REF TO cl_gbt_multirelated_service,

lo_recipient TYPE REF TO if_recipient_bcs.

DATA: l_filename TYPE string,

lt_soli TYPE soli_tab,

lt_solix TYPE solix_tab,

ls_soli TYPE soli,

ls_solix TYPE solix.

DATA: l_html_raw LIKE LINE OF html_data-content,

html_xstr TYPE xstring,

html_str TYPE string,

html_len TYPE i,

l_offset TYPE i,

l_length TYPE i,

l_diff TYPE i,

l_content_id TYPE string,

l_content_type TYPE w3conttype,

l_obj_len TYPE so_obj_len,

gr_xstr TYPE xstring,

l_gr_raw TYPE bapiconten,

l_username TYPE uname,

l_mail_address TYPE ad_smtpadr,

wa_return TYPE bapiret2.

DATA: lv_send_req_bcs TYPE REF TO cx_send_req_bcs,

lv_address_bcs TYPE REF TO cx_address_bcs,

lv_gbt_mime TYPE REF TO cx_gbt_mime,

lv_bcom_mime TYPE REF TO cx_bcom_mime,

lv_document_bcs TYPE REF TO cx_document_bcs.

CLEAR html_xstr.

LOOP AT p_html-content INTO l_html_raw.

CONCATENATE html_xstr l_html_raw INTO html_xstr IN BYTE MODE.

ENDLOOP.

html_xstr = html_xstr(p_html-length).

CALL FUNCTION 'SCP_TRANSLATE_CHARS' "#EC NOTEXT

EXPORTING inbuff = html_xstr

incode = '4110' " UTF-8 "#EC NOTEXT

  • OUTCODE = '0000' " ACTUAL CODEPAGE

csubst = 'X' "#EC NOTEXT

substc_space = 'X' "#EC NOTEXT

IMPORTING outbuff = html_str

outused = html_len

EXCEPTIONS OTHERS = 1.

  • CHANGE ENCODING UTF-8 TO LATIN1

REPLACE ALL OCCURRENCES OF 'UTF-8' IN html_str WITH 'iso-8859-1'

IGNORING CASE. "#EC NOTEXT

*HACK THE HTML CODE GENERATED BY SARTFORM TO MAKE THE

*EXTERNAL IMAGES APPEAR AS <IMG> TAG IN HTML

REPLACE ALL OCCURRENCES OF '<IMG' IN html_str WITH '<IMG' IGNORING

CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '/>' IN html_str WITH '/>' IGNORING

CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '</A>' IN html_str WITH ''

IGNORING CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '<' IN html_str WITH '<'

IGNORING CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '>' IN html_str WITH '>'

IGNORING CASE. "#EC NOTEXT

html_len = STRLEN( html_str ).

l_offset = 0.

l_length = 255.

WHILE l_offset < html_len.

l_diff = html_len - l_offset.

IF l_diff > l_length.

ls_soli-line = html_str+l_offset(l_length).

ELSE.

ls_soli-line = html_str+l_offset(l_diff).

ENDIF.

APPEND ls_soli TO lt_soli.

ADD l_length TO l_offset.

ENDWHILE.

CREATE OBJECT lo_mime_helper.

CALL METHOD lo_mime_helper->set_main_html

EXPORTING

content = lt_soli

filename = 'SAPWEBFORM.HTM' "#EC NOTEXT

description = 'SAP WEB FORM'. "#EC NOTEXT

LOOP AT p_graphics INTO l_graphic.

CLEAR gr_xstr.

LOOP AT l_graphic-content INTO l_gr_raw.

CONCATENATE gr_xstr l_gr_raw-line INTO gr_xstr IN BYTE MODE.

ENDLOOP.

gr_xstr = gr_xstr(l_graphic-length).

l_offset = 0.

l_length = 255.

CLEAR lt_solix[].

WHILE l_offset < l_graphic-length.

l_diff = l_graphic-length - l_offset.

IF l_diff > l_length.

ls_solix-line = gr_xstr+l_offset(l_length).

ELSE.

ls_solix-line = gr_xstr+l_offset(l_diff).

ENDIF.

APPEND ls_solix TO lt_solix.

ADD l_length TO l_offset.

ENDWHILE.

CONCATENATE c_gr_dir l_graphic-graphics

'.BMP' INTO l_filename. "#EC NOTEXT

CONCATENATE c_gr_dir l_graphic-graphics

'.BMP' INTO l_content_id. "#EC NOTEXT

l_content_type = l_graphic-httptype.

l_obj_len = l_graphic-length.

*Add images to the email

CALL METHOD lo_mime_helper->add_binary_part

EXPORTING

content = lt_solix

filename = l_filename

extension = 'BMP' "#EC NOTEXT

description = 'GRAPHIC IN BMP FORMAT' "#EC NOTEXT

content_type = l_content_type

length = l_obj_len

content_id = l_content_id.

ENDLOOP.

TRY.

lo_doc_bcs = cl_document_bcs=>create_from_multirelated(

i_subject = p_subject

i_multirel_service = lo_mime_helper ).

CATCH cx_document_bcs INTO lv_document_bcs.

  • ERROR HANDLING

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_document_bcs->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

CATCH cx_bcom_mime INTO lv_bcom_mime.

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_bcom_mime->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

CATCH cx_gbt_mime INTO lv_gbt_mime.

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_gbt_mime->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

ENDTRY.

  • REUSE THE CONTENT PREPARED FOR ALL RECEIVERS

LOOP AT p_receivers INTO receiver.

l_mail_address = receiver-receiver.

  • CREATE SEND_REQUEST

TRY.

lo_bcs = cl_bcs=>create_persistent( ).

lo_bcs->set_document( i_document = lo_doc_bcs ).

CATCH cx_send_req_bcs INTO lv_send_req_bcs.

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

ENDTRY.

  • CREATE SENDER

CLASS cl_cam_address_bcs DEFINITION LOAD.

TRY.

IF l_username NS '@'. "#EC NOTEXT

l_username = send_partner .

TRANSLATE l_username TO UPPER CASE. "#EC TRANSLANG

li_sender ?= cl_sapuser_bcs=>create( l_username ).

ELSE.

DATA: l_from_mail_address TYPE ad_smtpadr.

l_from_mail_address = l_username.

li_sender ?=

cl_cam_address_bcs=>create_internet_address(

i_address_string = l_from_mail_address ).

ENDIF.

CALL METHOD lo_bcs->set_sender

EXPORTING

i_sender = li_sender.

CATCH cx_address_bcs INTO lv_address_bcs.

  • ERROR HANDLING

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_address_bcs->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

CATCH cx_send_req_bcs INTO lv_send_req_bcs.

  • FAILED TO ADD A SENDER

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

EXIT.

EXIT.

ENDTRY.

  • CREATE RECIPIENT

TRY.

lo_recipient = cl_cam_address_bcs=>create_internet_address(

i_address_string = l_mail_address ).

CATCH cx_address_bcs INTO lv_address_bcs.

  • ERROR HANDLING

CONTINUE.

ENDTRY.

TRY.

lo_bcs->add_recipient( i_recipient = lo_recipient ).

CATCH cx_send_req_bcs INTO lv_send_req_bcs.

  • FAILED TO ADD A RECIPIENT

CONTINUE.

ENDTRY.

  • SEND

TRY.

  • RECEIPTS ONLY FOR ERRORS

CALL METHOD lo_bcs->send_request->set_requested_status

EXPORTING

i_requested_status = 'N'. "#EC NOTEXT

lv_sent_to_all = lo_bcs->send( ).

CATCH cx_send_req_bcs INTO lv_send_req_bcs.

CLEAR wa_return.

wa_return-type = 'E'. "#EC NOTEXT

MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.

INSERT wa_return INTO TABLE p_return.

  • ERROR HANDLING

EXIT.

ENDTRY.

ENDLOOP. " END LOOP AT P_RECEIVERS

COMMIT WORK.

  • set the success information

CLEAR wa_return.

  • MESSAGE i013 INTO WA_RETURN-MESSAGE. "Email sent successfully

*gpulido

WRITE /'Email sent successfully '.

*gpulido

INSERT wa_return INTO TABLE p_return.

ENDFORM. "SEND_HTML_EMAIL

Bye again

Gabriel

Former Member
0 Kudos

Hello,

You can do it like this...using SapScript:

REPORT YMAIL.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

***********************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

***********************************************************************

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file, would you check it?'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

BREAK gpulido.

  • Set recipient - email address here!!!

*MAILREC-RECEIVER = 'gabe_pu@hotmail.com'.

MAILREC-RECEIVER = 'rafamarfer@gmail.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

    • Set recipient - email address here!!!

*MAILREC-RECEIVER = 'BGIRALDO'.

*MAILREC-REC_TYPE = 'B'.

*APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

submit rsconn01 with mode = 'INT' and return.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT MAILREC.

WRITE: / mailrec-RECEIVER(48), ':'.

IF mailrec-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of'

.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

ENDFORM.

***********************************************************************

  • Form PREPARE_PACKING_LIST

***********************************************************************

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

***********************************************************************

  • Form GET_OTF_CODE

***********************************************************************

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'YSEND_MAIL'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

Bye...

Gabriel

Former Member
0 Kudos

hi Gabriel,,

can u please forward to me also

indnavid@gmail.com

Thanks in advance

Naveen khan