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: 

Messenger Mails from ABAP

Former Member
0 Kudos

Hi All,

I am from BI background. We have a requirement in which we need to send mails to particular users based on a value in the report.

Is it possible to send messenger mails from ABAP Program?

Thanks,

Sri Arun Prian

5 REPLIES 5

Former Member
0 Kudos

Hi,

You mean - email to external id.

Then Check these FM

SO_DOCUMENT_SEND_API1

SO_NEW_DOCUMENT_ATT_SEND_API1

SO_NEW_DOCUMENT_SEND_API1

SO_OLD_DOCUMENT_SEND_API1

Former Member
0 Kudos

Hi,

Refer this FM

SO_NEW_DOCUMENT_ATT_SEND_API1

Regards,

Jyothi CH.

Former Member
0 Kudos

Hi,

The FM provided my avinash is correct.

Follow this sample code:

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.

WRITE : 'over'.

Regards,

Naveen M.

Former Member
0 Kudos

Hi,

If you mean sending mails to external id then use the below code.

But this needs some configuration by the basis team


* Data Declarations
DATA: lt_mailsubject     TYPE sodocchgi1.
DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE.
DATA: lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE.
 
* Recipients
lt_mailrecipients-rec_type  = 'U'.
lt_mailrecipients-receiver = '<email>'.
APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .
 
* Subject.
lt_mailsubject-obj_name = 'TEST'.
lt_mailsubject-obj_langu = sy-langu.
lt_mailsubject-obj_descr = 'Mail Subject'.
 
* Mail Contents
lt_mailtxt = 'This is a test mail'.
APPEND lt_mailtxt. CLEAR lt_mailtxt.
 
* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    document_data              = lt_mailsubject
  TABLES
    object_content             = lt_mailtxt
    receivers                  = lt_mailrecipients
  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.
IF sy-subrc EQ 0.
  COMMIT WORK.
 
*   Push mail out from SAP outbox
  SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.

Regards,

Manish

Former Member