Sie sind auf Seite 1von 15

Configuring SAP SMTP service

SAP ECC permits sending and receiving of messages, including email. NetWeaver ABAP comes with
everything needed to set up the configuration. What is needed is an external email infrastructure to have a
usable mail configuration in SAP that allows for sending and receiving email:
External SMTP server. Acts as a SMTP server between SAP and the receiver. This is the email server used to send emails.
This can be the official SMTP server of the corporation or any other valid one, like Yahoo.
Route for incoming emails. As the MX DNS entry for a domain normally points to the SMTP server mentioned above, the
SAP SMTP server wont receive emails automatically. A forwarding rule between the SMTP server and the SAP SMTP
server needs to be configured.

Configuration of SMTP in SAP
Title Link
SAP Note:
455140 https://service.sap.com/sap/support/notes/455140
SAP Help http://help.sap.com/saphelp_nw70/helpdata/en/af/73563c1e734f0fe10000000a114084/content.htm

The steps are pretty simple. All are to be executed in the SAP system. I used the NPL Gateway Demo system for this.

1. Open the port for SMTP
Transaction: RZ10

In case this was not done before, import the profiles

Select the right profile (here: instance profile) and the Extended maintenance option.

To receive emails on an SMTP port, ICM needs to be configured to
1. Open the port and to
2. Use protocol SMTP

Add an entry for SMTP in the instance profile. Here, the port used is 25000.

Save changes to instance profile.

Then save and activate the changes.

Warning message informs that a ICM restart is needed to activate the changes.

Looking in the profile file on the server:

ICM profile file is changed, change is persisted in the file but ICM does not pick up the new configuration automatically.
A restart of ICM is needed.
Transaction: SMICM

The Restart option didnt work for me, a hard exit with a start activated the change. But I am not Basis person.

Confirm the restart of ICM.

Check the SMTP service details. They have to match the new configuration.

Verifying the ICM parameters using SAP MMC.

2. Create system user for receiving emails
Transaction: SU01

Make sure the users in the SAP system have an email address configured.

Here I am using tobias@mydomain.com
With this configuration, email send to the SAP SMTP server will be picked up and delivered into the users inbox.

3. Configure SMTP service

Transaction: SICF


Check that the virtual SMTP
server is configured

The logon data has to be
configured to use the above
created SMTPUSER

Handler list


Save the changes and activate the service.

Configure the SMTP server and outbound and inbound flow
1. SMTP server
Transaction: SCOT

Set the default domain

This domain matches the email domain of the users.

a. Outbound
View: Nodes view

Set the outgoing SMTP server

Note: This is the SMTP server the SAP system will use to actually send the emails. Emails get send to
this SMTP server and from there they are being send to the actual recipient. That is, the server
defined has the responsibility to lookup the MX entry of the receiving domain.

Set the address type this node does accept

Note: In the address area, insert the valid format of email addresses. When you insert * the node will
accept every email address. To make this node only accept email addresses for a specific user, put
<username>@domain.tld


Result in node view

Now the node is configured to accept outgoing emails. What is missing is a job that picks up the
emails from the outgoing queue and sends them. Create a job that will send the queued messages
View: Job view



Select SAP&CONNECTALL or SAP&CONNECTINT for sending internet email

To run the job immediately, select Start immediately. To schedule a job so it is executed at a
defined interval, select Schedule

To schedule


Result

a. Inbound
As long as the virtual SMTP server is activated and the system user has the right permission AND a
user with the correct email address exists, inbound processing of emails will work.
FUNCTION ZNPI_SEND_MAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(SUBJECT) TYPE SO_OBJ_DES
*" VALUE(MESSAGE_BODY) TYPE BCSY_TEXT
*" VALUE(ATTACHMENTS) TYPE RMPS_T_POST_CONTENT OPTIONAL
*" VALUE(SENDER_UID) TYPE SYUNAME OPTIONAL
*" VALUE(RECIPIENT_UID) TYPE SYUNAME OPTIONAL
*" VALUE(SENDER_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL
*" VALUE(RECIPIENT_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL
*" EXPORTING
*" VALUE(RESULT) TYPE BOOLEAN
*" TABLES
*" RECIPIENTS STRUCTURE UIYS_IUSR OPTIONAL
*"----------------------------------------------------------------------
*Data Declaration
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
l_send type ADR6-SMTP_ADDR ,
l_rec type ADR6-SMTP_ADDR .
Data : ITAB TYPE TABLE OF SVAL,
LS_ITAB TYPE SVAL,
i_RETURN.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
* DATA:
* lt_message_body TYPE bcsy_text VALUE IS INITIAL,
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL,
attachment_subject type SO_OBJ_DES.

DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
data: ls_recipient like line of recipients,
ls_attachment like line of attachments.
DATA: lv_recipient_uid TYPE uname,
lv_recipient_mail TYPE adr6-smtp_addr.

*Prepare Mail Object
CLASS cl_bcs DEFINITION LOAD.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
data: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = message_body
i_subject = subject ).



*Send attachment
loop at attachments into ls_attachment.
attachment_subject = ls_attachment-subject.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = ls_attachment-OBJTP
i_attachment_subject = attachment_subject

i_att_content_hex = ls_attachment-CONT_HEX ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
endloop.

* Pass the document to send request
lo_send_request->set_document( lo_document ).
try.
if sender_mail is not initial.
lo_sender = cl_cam_address_bcs=>create_internet_address(
sender_mail ).
elseif sender_uid is not initial.
lo_sender = cl_sapuser_bcs=>create( sender_uid ).
else.
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
endif.
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
catch CX_ADDRESS_BCS.
return.
endtry.
* Set recipients
if recipients[] is initial.

if recipient_mail is not initial.
lo_recipient = cl_cam_address_bcs=>create_internet_address(
recipient_mail ).
elseif recipient_uid is not initial.
lo_recipient = cl_sapuser_bcs=>create( recipient_uid ).
else.
lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
endif.

lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
else.

loop at recipients into ls_recipient.
if ls_recipient-iusrid is not initial.
lv_recipient_uid = ls_recipient-iusrid.
lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ).
elseif ls_recipient-email is not initial.
lv_recipient_mail = ls_recipient-email .
lo_recipient = cl_cam_address_bcs=>create_internet_address(
lv_recipient_mail ).
endif.

lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).

endloop.
endif.
try.
** Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = result ).
COMMIT WORK.
wait up to 1 seconds.
catch cx_send_req_bcs.
result = ''.
endtry.
ENDFUNCTION.
http://wiki.scn.sap.com/wiki/display/ABAP/Sending+Mails+-+Home+Page