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

STEP 1: Take help from R/3 Basis to maintain the user(s) in SU0, SU02 and SCOT transactions and maintain email addresses and IP address as well as port of the mail server in the SMTP settings. For the settings please refer SAP note 455140.

STEP 2: Take help from N&S team to get the SMTP relay access unblocked for the R/3 server to send the mail to the mail server.

STEP 3: The code written for sending of mail from SAP R/3 backend to outlook is as below;

*&---------------------------------------------------------------------*
*& Report ZPS_MAIL_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZPS_MAIL_TEST.
PARAMETERS: PSUBJECT(40) TYPE C DEFAULT 'hi. finally you got it.',
P_EMAIL(40) TYPE C DEFAULT 'pramesh@satyam.com'.
DATA: IT_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
IT_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
IT_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
IT_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
GD_CNT TYPE I,
GD_SENT_ALL(1) TYPE C,
GD_DOC_DATA LIKE SODOCCHGI1,
GD_ERROR TYPE SY-SUBRC.
DATA: IT_MESSAGE TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
WITH HEADER LINE.
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
PERFORM POPULATE_MESSAGE_TABLE.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM SEND_EMAIL_MESSAGE.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
*&---------------------------------------------------------------------*
*& Form POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
* Adds text to email text table
*----------------------------------------------------------------------*
FORM POPULATE_MESSAGE_TABLE.
APPEND 'hi there,this is a test program.' TO IT_MESSAGE.
APPEND 'to send mail from SAP R3' TO IT_MESSAGE.
APPEND 'by pramesh sardessai.' TO IT_MESSAGE.
ENDFORM. "populate_message_table
* "POPULATE_MESSAGE_TABLE
This document is property of Pramesh Sardessai
*&---------------------------------------------------------------------*
*& Form SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
* Send email message
*----------------------------------------------------------------------*
FORM SEND_EMAIL_MESSAGE.
* Fill the document data.
* gd_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
GD_DOC_DATA-OBJ_LANGU = SY-LANGU.
GD_DOC_DATA-OBJ_NAME = 'SAPRPT'.
GD_DOC_DATA-OBJ_DESCR = PSUBJECT.
GD_DOC_DATA-SENSITIVTY = 'S'.
GD_DOC_DATA-NO_CHANGE = SPACE.
* Describe the body of the message
CLEAR IT_PACKING_LIST.
REFRESH IT_PACKING_LIST.
IT_PACKING_LIST-TRANSF_BIN = SPACE.
IT_PACKING_LIST-HEAD_START = 1.
IT_PACKING_LIST-HEAD_NUM = 0.
IT_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE IT_MESSAGE LINES IT_PACKING_LIST-BODY_NUM.
IT_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND IT_PACKING_LIST.
* Add the recipients email address
CLEAR IT_RECEIVERS.
REFRESH IT_RECEIVERS.
IT_RECEIVERS-RECEIVER = P_EMAIL.
* it_receivers-rec_id = 'DEVELOPER'.
IT_RECEIVERS-REC_TYPE = 'U'.
IT_RECEIVERS-COM_TYPE = 'INT'.
* it_receivers-notif_del = 'X'.
* it_receivers-notif_ndel = 'X'.
APPEND IT_RECEIVERS.
* Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = GD_DOC_DATA
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = GD_SENT_ALL
TABLES
PACKING_LIST = IT_PACKING_LIST
CONTENTS_TXT = IT_MESSAGE
RECEIVERS = IT_RECEIVERS
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
* Store function module return code
GD_ERROR = SY-SUBRC.
* Get it_receivers return code
LOOP AT IT_RECEIVERS.
ENDLOOP.
ENDFORM. " SEND_EMAIL_MESSAGE
This document is property of Pramesh Sardessai
*&---------------------------------------------------------------------*
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
* Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM INITIATE_MAIL_EXECUTE_PROGRAM.
WAIT UP TO 2 SECONDS.
IF GD_ERROR EQ 0.
SUBMIT RSCONN01 WITH MODE = 'INT'
WITH OUTPUT = 'X'
AND RETURN.
ENDIF.

STEP 4: Change the code as per requirements. Settings can be done for attachments, cc and bcc.

PS: Please note that this settings/code sends mail from mentioned R/3 to Outlook Express and not to MS Outlook because of security and limitations of SMTP relay to inter domain.

 

  • No labels