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 mail from ABAP

Former Member
0 Kudos
995

Hi Guys,

I know there has been several post about this but i can get it to work.

I have taken the example from function module.

The sending of an express document to an internal user work.

But as soon as i use receiver type U i dont get anything send.

In the end i get

&ADU00100000094 : succesfully sent
RASS            : succesfully sent

This means that the my@email.com has been deleted an it is only showing the id.

Here is my code.

REPORT  ZMON_SEND_MAIL3                         .
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).

* Fill the document
DOC_CHNG-OBJ_NAME = 'URGENT... Not'.
DOC_CHNG-OBJ_DESCR = 'Read at once !'.
DOC_CHNG-SENSITIVTY = ''.
OBJCONT = 'Hey guys, time for lunch !!!'.
APPEND OBJCONT.
OBJCONT = 'Lets get going !'.
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 = 'my@email.com'.
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.

I have test through the work place that I am able to send email out of the house.

So the SMTP server is working.

Any help is appreciated.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
320

Rasmus,

ADD parameter:

COMMIT_WORK = 'X'

to your CALL FUNCTION

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_TYPE = 'RAW'

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X' " <---- here

TABLES

6 REPLIES 6

Former Member
0 Kudos
320

Hi,

Go and check in the Transaction SCOT if some mails are waiting toi be send..

Thanks

Mahesh

0 Kudos
320

I did.

No mail are coming through from the abap.

I can see it in the workplace though.

From here I also tried to send it to my mail.

And this works fine, it shows in transaction SCOT and is delivered to my mail.

But the abap is not working.

former_member194669
Active Contributor
0 Kudos
320

Hi,

Try this way


REPORT  ZMON_SEND_MAIL3                         .
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).
 
* Fill the document
DOC_CHNG-OBJ_NAME = 'URGENT... Not'.
DOC_CHNG-OBJ_DESCR = 'Read at once !'.
DOC_CHNG-SENSITIVTY = ''.
OBJCONT = 'Hey guys, time for lunch !!!'.
APPEND OBJCONT.
OBJCONT = 'Lets get going !'.
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.

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.

CLEAR RECLIST. REFRESH RECLIST.
RECLIST-RECEIVER = 'my@email.com'.
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.

COMMIT WORK.

aRs

Former Member
0 Kudos
321

Rasmus,

ADD parameter:

COMMIT_WORK = 'X'

to your CALL FUNCTION

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_TYPE = 'RAW'

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X' " <---- here

TABLES

0 Kudos
320

Thanks a lot, the commit parameter was missing.

Former Member
0 Kudos
320

Hi,

Just put a commit work and wait at the end of your coding.

That should do the trick.

Brest regards,

Dirk.