Application Development 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: 

Sending Email

Former Member
0 Kudos
85

I have a requirement wherein I need to send mail to SAP business workplace. Let me know which function module can be used for this purpose. It would be grateful if a sample code is attached.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
53

Pl. use the below code which will be useful.

report zmail.

data : maildata type sodocchgi1,

mailtxt type table of solisti1 with header line,

mailrec type table of somlrec90 with headerline.

start-of-selection.

clear : maildata, mailtxt, mailrec.

refresh : mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test'.

maildata-obj_langu = sy-langu.

mailtxt-line = 'Sending Mail'.

append mailtxt.

mailrec-receiver = 'xxxx@xxx.com'.

mailrec-rec_ty[e = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'RAW'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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.

Pl. award points if useful.

3 REPLIES 3

vinod_gunaware2
Active Contributor
0 Kudos
53

SAP Send mail via ABAP functions SO_NEW_DOCUMENT_SEND_API1

This abap mail sending program demonstrate how you can send a mail to the user SAP Office mailbox.

REPORT ZSEND .

TABLES: KNA1.

  • data for send function

DATA DOC_DATA LIKE SODOCCHGI1.

DATA OBJECT_ID LIKE SOODK.

DATA OBJCONT LIKE SOLI OCCURS 10 WITH HEADER LINE.

DATA RECEIVER LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.

SELECT * FROM KNA1 WHERE ANRED LIKE 'C%'.

WRITE:/ KNA1-KUNNR, KNA1-ANRED.

  • send data internal table

CONCATENATE KNA1-KUNNR KNA1-ANRED

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

ENDSELECT.

  • insert receiver (sap name)

REFRESH RECEIVER.

CLEAR RECEIVER.

MOVE: SY-UNAME TO RECEIVER-RECEIVER,

'X' TO RECEIVER-EXPRESS,

'B' TO RECEIVER-REC_TYPE.

APPEND RECEIVER.

  • insert mail description

WRITE 'Sending a mail through abap'

TO DOC_DATA-OBJ_DESCR.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

IMPORTING

NEW_OBJECT_ID = OBJECT_ID

TABLES

OBJECT_CONTENT = OBJCONT

RECEIVERS = RECEIVER

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.

regards

vinod

Former Member
0 Kudos
54

Pl. use the below code which will be useful.

report zmail.

data : maildata type sodocchgi1,

mailtxt type table of solisti1 with header line,

mailrec type table of somlrec90 with headerline.

start-of-selection.

clear : maildata, mailtxt, mailrec.

refresh : mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test'.

maildata-obj_langu = sy-langu.

mailtxt-line = 'Sending Mail'.

append mailtxt.

mailrec-receiver = 'xxxx@xxx.com'.

mailrec-rec_ty[e = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'RAW'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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.

Pl. award points if useful.

Former Member