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: 

My code to send email does not work...

aris_hidalgo
Contributor
0 Kudos

Hello experts,

I am trying to send email to users after adding a new record. Now, it does not work properly. Below is the code I made. Please help me out on this guys. Again, thank you guys and have a nice day!

  • For API

DATA: maildata TYPE sodocchgi1.

DATA: mailtxt TYPE TABLE OF solisti1 WITH HEADER LINE.

DATA: mailrec TYPE TABLE OF somlrec90 WITH HEADER LINE.

CLEAR: maildata, mailtxt, mailrec.

REFRESH: mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test'.

maildata-obj_langu = sy-langu.

mailtxt-line = 'This is a test'.

APPEND mailtxt.

SELECT * FROM zshipto_email

INTO TABLE it_zshipto_email.

LOOP AT it_zshipto_email.

mailrec-receiver = it_zshipto_email-zemail.

mailrec-rec_type = 'U'.

APPEND mailrec.

ENDLOOP.

delete mailrec where receiver is initial.

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.

commit work.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Message was edited by: viraylab

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi viraylab,

1. Please specify

COMMIT_WORK = 'X'

in this FM.

2. Then once again check.

3. Also check in SCOT transaction.

regards,

amit m.

7 REPLIES 7

Former Member
0 Kudos

Are you setting the parameter COMMIT_WORK = 'X' in the function call SO_NEW_DOCUMENT_SEND_API1?

the COMMIT WORK has been introduced only from 47 onward.. Since, you are on 46c it is not required

otherwise..

check TCode SOST for any additional info that could be helpful for u...

and at last just check the vijay reply in this thread complete code....

Former Member
0 Kudos

Hai

check the following Code

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA L_NUM(3).

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.

  • Mail Contents

OBJTXT = 'Object text'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

LOOP AT ITAB_DATA.

CONCATENATE ITAB_DATA-PRODUCTOR

ITAB_DATA-VBELN

ITAB_DATA-POSNR

ITAB_DATA-MATNR INTO OBJBIN.

APPEND OBJBIN.

ENDLOOP.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'ORDERS'.

APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'WEBSITE'.

OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

  • Completing the recipient list

  • target recipent

clear RECLIST.

RECLIST-RECEIVER = 'test@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • copy recipents

clear RECLIST.

RECLIST-RECEIVER = 'secondtest@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

RECLIST-COPY = 'X'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

Thanks & regards

Sreeni

Former Member
0 Kudos

Hi viraylab,

1. Please specify

COMMIT_WORK = 'X'

in this FM.

2. Then once again check.

3. Also check in SCOT transaction.

regards,

amit m.

0 Kudos

Hello again friends,

I included the commit_work = 'X' but it still doesnt work.

0 Kudos

Hi again,

1. Please check in SCOT tcode.

2. The mail message must be in waiting.

3. The mail message is not sent immediately.

4. We may have to manually go and

send from SCOT.

regards,

amit m.

0 Kudos

I am encountering a message error. It says that

"Cannot transfer message to node SMTP due to RFC error".

Again, thank you guys for your help!

0 Kudos

Hi again,

1. For this u will have to take help

of basis team,

for proper settings of SCOT.

2. If u can see your email message

in scot (waiting for send)

then your code is working fine.

3. Only scot settings( which are done by basis team)

will need to be done/corrected.

regards,

amit m.