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

Sending Mail through Program

Former Member
0 Likes
919

Hi Experts,

My requirement is to send mail through ABAP program.

I am doing it by the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

Allthough the subrc = 0, but no mail is being received at the id.

The Code is as follows :

REPORT ZTEST1.

DATA : gd_doc_data TYPE sodocchgi1,

it_packing_list TYPE STANDARD TABLE OF sopcklsti1,

wa_packing_list like line of it_packing_list,

li_reclist TYPE STANDARD TABLE OF somlreci1,

gd_sent_all(1) type c,

it_message type standard table of SOLISTI1,

it_receivers type standard table of somlreci1,

wa_receivers like line of it_receivers.

************************************************************************

  • Data of an object which can be changed

gd_doc_data-doc_size = 1.

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = 'TESTING'.

gd_doc_data-sensitivty = 'F'.

************************************************************************

Append 'Line1' to it_message.

Append 'Line2' to it_message.

Append 'Line3' to it_message.

Append 'Test- 1' to it_message.

wa_receivers-receiver = <mail_id>.

wa_receivers-rec_type = 'U'.

append wa_receivers to it_receivers.

wa_packing_list-transf_bin = space.

wa_packing_list-head_start = 1.

wa_packing_list-head_num = 0.

wa_packing_list-body_start = 1.

describe table it_message lines wa_packing_list-body_num.

wa_packing_list-doc_type = 'RAW'.

append wa_packing_list to it_packing_list.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = gd_doc_data

PUT_IN_OUTBOX = 'X'

  • COMMIT_WORK = ' '

IMPORTING

SENT_TO_ALL = gd_sent_all

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = it_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN =

CONTENTS_TXT = it_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = it_receivers

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 <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

8 REPLIES 8
Read only

Former Member
0 Likes
892

Hi Ravi,

Check in TCODE SOST if the status of the mail is visible ?

Regards

Read only

0 Likes
892

Hey Rajnish,

I cannot see the mail in SOST.

Thanks and Regards,

Ravi Bhatnagar

Read only

0 Likes
892

Hi,

In the documentation for function module SO_NEW_DOCUMENT_ATT_SEND_API1 there is a standard code for sending mails. Execute this and check in TCODE SOST.

If this works then you can identify where the problem is

REPORT  ZSSO_DOCUMENT_SEND_API1.

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.

* Creating the document to be sent
DOC_CHNG-OBJ_NAME = 'OFFER'.
DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.
OBJTXT = 'Reserve price : $250000'.
APPEND OBJTXT.
OBJTXT = 'A reproduction of the painting to be auctioned'.
APPEND OBJTXT.
OBJTXT = 'is enclosed as an attachment.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
* Creating 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.
* Creating the document attachment
* (Assume the data in OBJBIN are given in BMP format)
OBJBIN = ' \O/ '. APPEND OBJBIN.
OBJBIN = '     '. APPEND OBJBIN.
OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.
* Creating 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   = 'BMP'.
OBJPACK-OBJ_NAME   = 'ATTACHMENT'.
OBJPACK-OBJ_DESCR = 'Reproduction object 138'.
OBJPACK-DOC_SIZE   = TAB_LINES * 255.
APPEND OBJPACK..
* Entering names in the distribution list
RECLIST-RECEIVER = <mailid>.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
RECLIST-RECEIVER = 'DLI-NEUREICH'.
RECLIST-REC_TYPE = 'P'.
APPEND RECLIST.
* Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
          DOCUMENT_DATA = DOC_CHNG
          PUT_IN_OUTBOX = 'X'
          COMMIT_WORK   = 'X'
     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.
CASE SY-SUBRC.
  WHEN 0.
    WRITE: / 'Result of the send process:'.
    LOOP AT RECLIST.
      WRITE: / RECLIST-RECEIVER(48), ':'.
      IF RECLIST-RETRN_CODE = 0.
        WRITE 'sent successfully'.
      ELSE.
        WRITE 'not sent'.
      ENDIF.
    ENDLOOP.
  WHEN 1.
    WRITE: / 'no authorization to send to the specified number of'
'recipients!'.
  WHEN 2.
    WRITE: / 'document could not be sent to any of the recipients!'.
  WHEN 4.
    WRITE: / 'no authorization to send !'.
  WHEN OTHERS.
    WRITE: / 'error occurred during sending !'.
ENDCASE.

Regards

Read only

0 Likes
892

Hey Rajvansh,

I have used to program given in the FM documentation to send a mail.

I can see the mail in SOST also.

However, I am not able to see the mail in the inbox which I specified.

Regards,

Ravi Bhatnagar

Read only

0 Likes
892

Hi Ravi,

What is the status in SOST. is it red ?

May be background job needs to be started.

In SOST click on the message and press "Start send process for selection "

Check after few seconds in your ID when the status becomes green

Regards

Read only

Former Member
0 Likes
892

hi,

Check out the configurations and port settings, try configuring them, they might be creating an issue in sending the mail.

Thanks

Sharath

Read only

Former Member
0 Likes
892

Hi,

Refer the given below link

/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2...

Thanks

Arun Kayal

Read only

Former Member
0 Likes
892

Hi

Check this wiki in sap.sdn it will usefull

https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/sendMessagetoExternalemailidandSAPUseridvia+ABAP

Regards,

Syf