Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Back to Sending Mails - Home Page

* Before using following CODE, Need to Create ITS Service for SAP Trasaction thru tcode : SICF

Note : read comments for more details.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
* Data Declaration related to SAP Link Creation for TRIP
*********************************************************
DATA : wda_name     TYPE string,
       in_protocol  TYPE string,
       out_host     TYPE string,
       out_port     TYPE string,
       out_protocol TYPE string,
       val          TYPE string,
       g_url        TYPE string.

* Data Declaration related to Mail
***********************************
DATA :  send_request       TYPE REF TO cl_bcs,
   document           TYPE REF TO cl_document_bcs,
   send TYPE REF TO if_sender_bcs,
   i_text TYPE soli_tab,
   wa_text TYPE soli,
   receiver          TYPE REF TO if_recipient_bcs,
   sent_to_all        TYPE os_boolean,
   sender TYPE adr6-smtp_addr,
   recipient TYPE adr6-smtp_addr,
   subject TYPE so_obj_des.
DATA : temp_addr TYPE adr6-smtp_addr.
***********************************

*********************************************************
* -Generating URL for SAP Trasaction ( SAP GUI for HTML )
*********************************************************
CALL METHOD cl_http_server=>if_http_server~get_location
  EXPORTING
    protocol     = in_protocol
    server       = cl_wdr_task=>server
  IMPORTING
    host         = out_host
    port         = out_port
    out_protocol = out_protocol.

val = sy-mandt.
CONCATENATE out_protocol '://' out_host ':' out_port '/sap/bc/gui/sap/its/ztrip' INTO g_url.
*                                 "  /sap/bc/gui/sap/its/ path for ITS service
*                                 "  ztrip service name for TCODE - TRIP, created thru SICF
CALL METHOD cl_http_server=>append_field_url
  EXPORTING
    name  = 'sap-client'
    value = val
  CHANGING
    url   = g_url.

***************************************
* Sending mail to Outlook with SAP link
***************************************

send_request = cl_bcs=>create_persistent( ).
CONCATENATE 'Dear SDN,' '' INTO wa_text-line.
APPEND wa_text-line TO i_text.

CONCATENATE 'Please find below link for Travel Request ( TRIP ),' '' INTO wa_text-line.
APPEND wa_text-line TO i_text.

CONCATENATE '<a href="' g_url '"  > Link to Travel Request </a>' ' ' INTO wa_text-line.
APPEND wa_text-line TO i_text.

subject = 'SDN : Mail to Outlook with SAPLink'.
document = cl_document_bcs=>create_document(
                       i_type    = 'RAW'
                       i_text    = i_text
                       i_length  = '18'
                       i_subject = subject ).

* add document to send request
CALL METHOD send_request->set_document( document ).

* create internet address for the sender
send = cl_cam_address_bcs=>create_internet_address(
                                 i_address_string = 'SDN@SAP.COM'
                                 i_address_name = 'SAP SDN').

* set the sender to send_request instance
CALL METHOD send_request->set_sender
  EXPORTING
    i_sender = send.

temp_addr = 'sdn@sap.com'. " Receiving Address
receiver = cl_cam_address_bcs=>create_internet_address(
                                        temp_addr  ). " adding receipts

CALL METHOD send_request->add_recipient
  EXPORTING
    i_recipient = receiver
    i_express   = 'X'.

send_request->set_send_immediately( 'X' ).

* sending the mail
CALL METHOD send_request->send(
  EXPORTING
    i_with_error_screen = 'X'
  RECEIVING
    result              = sent_to_all ).
IF sent_to_all = 'X'.
  WRITE :/ 'Mail has sent successfully'.
ENDIF.