Skip to Content
0
Former Member
Aug 13, 2007 at 02:20 PM

Sending mail from ABAP

656 Views

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.