Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sending Internal Emails

Former Member
0 Likes
959

Hi All,

How can I send SAP internal email to a user using ABAP Program ?

Hi All,

How can I send SAP internal email to a user using ABAP Program ?

6 REPLIES 6
Read only

amit_khare
Active Contributor
0 Likes
908

Welcome to SDN.

Use any of following FM -

'SO_NEW_DOCUMENT_ATT_SEND_API1'

'SO_NEW_DOCUMENT_SEND_API1'

'SO_OBJECT_SEND'

Check this thread -

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
908

Hi Syed,

Execute SE37 and enter MAIL* then press F4. It will display all the function module list for using to send mail.

Hope this helps you and reply for any queries.

Regards,

Kumar.

Read only

Former Member
0 Likes
908

Hi Syed,

Execute SE37 and enter <b>_MAIL_*</b> then press F4. It will display all the function module list for using to send mail.

Hope this helps you and reply for any queries.

Regards,

Kumar.

Read only

Former Member
0 Likes
908

See the following ex:

DATA: BEGIN OF EMAIL_DATA.

INCLUDE STRUCTURE SODOCCHGI1.

DATA: END OF EMAIL_DATA.

DATA: BEGIN OF EMAIL_SEND OCCURS 10.

INCLUDE STRUCTURE SOMLRECI1.

DATA: END OF EMAIL_SEND.

IF NOT I_MSG1[] IS INITIAL.

SELECT * FROM ZMMINT_USR INTO CORRESPONDING FIELDS OF TABLE IT_USR

WHERE WERKS = C_PLANT AND TX_ID = 'ZINC'.

IF SY-SUBRC = 0.

LOOP AT IT_USR.

EMAIL_DATA-OBJ_NAME = 'MESSAGE'.

EMAIL_DATA-OBJ_DESCR = 'PARK CUSTOM INVOICE'.

EMAIL_DATA-OBJ_LANGU = 'E'.

EMAIL_DATA-SENSITIVTY = 'P'.

EMAIL_DATA-OBJ_PRIO = '1'.

EMAIL_DATA-NO_CHANGE = 'X'.

EMAIL_DATA-PRIORITY = '1'.

EMAIL_SEND-RECEIVER = IT_USR-UNAME. "Receiver ID

EMAIL_SEND-REC_TYPE = 'B'.

  • EMAIL_SEND-EXPRESS = 'X'.

  • EMAIL_SEND-REC_ID = sy-uname.

APPEND EMAIL_SEND.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = EMAIL_DATA

DOCUMENT_TYPE = 'RAW'

PUT_IN_OUTBOX = 'X'

TABLES

OBJECT_CONTENT = I_MSG1

RECEIVERS = EMAIL_SEND.

ENDIF.

ENDIF.

Read only

Former Member
0 Likes
908

Hi

Find program below

<b>REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default '[email protected]' .

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 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

&----


*& 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 = 'F'.

  • 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_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'

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

&----


*& 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.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM</b>

Don't forget for reward points.

Reg,

Hiren Patel

Read only

Former Member
0 Likes
908

hai all thanks a lot for ur information..

The Functional module sent by Sadiqulla Shaik

was pretty very useful..then u very much..