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

sample code to send a mail from SAP

Former Member
0 Likes
1,651

Hi guys

could any one provide me with the

sample code to send a mail from SAP with text as the main body of that mail via bcs classes

1 ACCEPTED SOLUTION
Read only

former_member195698
Active Contributor
0 Likes
1,510

Search in the forum. There are a lot of threads on the same question

13 REPLIES 13
Read only

former_member195698
Active Contributor
0 Likes
1,511

Search in the forum. There are a lot of threads on the same question

Read only

0 Likes
1,510

i dint find

Read only

0 Likes
1,510

Use FM <b>SO_OBJECT_SEND</b>

Regards

Aneesh.

Read only

0 Likes
1,510

i wanted the text in main body of the email and not as attachments that too only when sending the mails thru Bcs classes

so please let me know if you find any discussion on this

Read only

0 Likes
1,510

Kittu,

This FM module does send text in the body but I am not sure whether it does so thru Bcs classes.

Regards

Aneesh.

Read only

0 Likes
1,510

hi aneesh thanks for the response iam already usin bcs classes to send out the mail but what ever i am trying to send for

cl_document_bcs=>create_document

is creating the mail in attachment where as i need the mail in the body of the mail

Read only

0 Likes
1,510

Kittu,

Send me your mail id, i will send you the code, to send data to mail body.

Regards,

Satish

Read only

0 Likes
1,510

Kittu,

Maybe this will be of help to you.

<a href="/people/thomas.jung3/blog/2005/01/05/develop-a-web-service-that-sends-an-email--in-abap Log</a>

Regards

Aneesh.

Read only

0 Likes
1,510

.

Read only

0 Likes
1,510

Hi satish

kittu_b4u2003@yahoo.co.in

is my ID ,please send the code

Read only

0 Likes
1,510

Sent sir....

Read only

0 Likes
1,510

thanks a lot

awarded solved sir

Read only

Former Member
0 Likes
1,510

Hi,

Please go through this code: U can send mail;

Tables : zchp_cust-info.

DATA: OBJCONT LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: ENTRIES LIKE SY-TABIX.

DATA: NAME(15).

DATA: CON_NAME(20).

DATA: req_num like zchp_cust_info.

DATA: I_TAB_CHP LIKE ZCHP_CUST_INFO OCCURS 0 WITH HEADER LINE.

*data: reno like ZCHP_CUST_INFO-req_num value .

  • data input for the mail

select * from zchp_cust_info

appending table i_tab_chp where req_num = c_knumv.

LOOP AT I_TAB_CHP.

concatenate i_tab_chp-created_by i_tab_chp-req_num into CON_NAME.

*WRITE: / con_name.

ENDLOOP.

  • Fill the document

DOC_CHNG-OBJ_NAME = 'Refe'.

DOC_CHNG-OBJ_DESCR = 'TESCRA Ref Number !'.

DOC_CHNG-SENSITIVTY = 'P'.

*OBJCONT = 'Tescra'.

OBJCONT = CON_NAME.

APPEND OBJCONT.

OBJCONT = con_name.

APPEND OBJCONT.

DESCRIBE TABLE OBJCONT LINES ENTRIES.

READ TABLE OBJCONT INDEX ENTRIES.

DOC_CHNG-DOC_SIZE = ( ENTRIES - 1 ) * 255 + STRLEN( OBJCONT ).

  • Fill the receiver list

CLEAR RECLIST.

RECLIST-RECEIVER = SY-UNAME. " replace with <login name>

RECLIST-REC_TYPE = 'B'.

RECLIST-EXPRESS = 'X'.

APPEND RECLIST.

CLEAR RECLIST.

RECLIST-RECEIVER = 'sapuser'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • Send the document

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_TYPE = 'RAW'

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

TABLES

OBJECT_CONTENT = OBJCONT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

LOOP AT RECLIST.

IF RECLIST-RECEIVER = SPACE.

NAME = RECLIST-REC_ID.

ELSE.

NAME = RECLIST-RECEIVER.

ENDIF.

IF RECLIST-RETRN_CODE = 0.

WRITE: / NAME, ': succesfully sent'.

ELSE.

WRITE: / NAME, ': error occured'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'Too many receivers specified !'.

WHEN 2.

WRITE: / 'No receiver got the document !'.

WHEN 4.

WRITE: / 'Missing send authority !'.

WHEN OTHERS.

WRITE: / 'Unexpected error occurred !'.

ENDCASE.

<b>Please provide points if the issue is solved.</b>

Regards,

Sunil