Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

problem in sending mail with attachment

Hi All,

I am using the function module <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b> to send mail with attachment.

the program executes properly and shows a message <b>'Document Sent'</b>. But neither the sent mail appears in <b>'SOST'</b> nor I get it on the specified email id.

Below is my code:

<b>***</b> As attachment I am sending resume whose contents are stored in table 'ZResume' corresponding to personnel no.(pernr) and serial No.(srno).

-


<b>START OF PROGRAM</b>----


REPORT ZPTEST_SEND_MAIL_ATTATCHMENT.

DATA : w_name TYPE sos04-l_adr_name.

DATA: RESUME TYPE table of XSTRING with header line.

*----


START-OF-SELECTION.

<b>* Data Declaration</b>

DATA:

l_datum(10),

ls_docdata TYPE sodocchgi1,

lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,

lt_listobject TYPE TABLE OF abaplist WITH HEADER LINE,

l_tab_lines TYPE i,

l_att_type LIKE soodk-objtp.

WRITE sy-datum TO l_datum.

SELECT SINGLE RESUME FROM ZRESUME INTO RESUME

WHERE PERNR EQ '00001182'

AND SRNO EQ '1'.

APPEND RESUME.

<b>* Because RESUME may be of size RAW(1000)

  • and objbin is of size CHAR(255) we make this table copy</b>

CALL FUNCTION 'TABLE_COMPRESS'

TABLES

in = resume

out = lt_objbin

EXCEPTIONS

compress_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • Error in function module &1

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

<b>* Create the message and send the document.

  • Create Message Body</b>

<b>* Title and Description</b>

ls_docdata-obj_name = 'Resume'.

ls_docdata-obj_descr = 'Resume'.

<b>* Main Text</b>

lt_objtxt = 'Resume of the candidate' .

APPEND lt_objtxt.

<b>* Write Packing List (Main)</b>

DESCRIBE TABLE lt_objtxt LINES l_tab_lines.

READ TABLE lt_objtxt INDEX l_tab_lines.

ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).

CLEAR lt_objpack-transf_bin.

lt_objpack-head_start = 1.

lt_objpack-head_num = 0.

lt_objpack-body_start = 1.

lt_objpack-body_num = l_tab_lines.

lt_objpack-doc_type = 'RAW'.

APPEND lt_objpack.

<b>* Create Message Attachment

  • Write Packing List (Attachment)</b>

l_att_type = 'ALI'.

DESCRIBE TABLE lt_objbin LINES l_tab_lines.

READ TABLE lt_objbin INDEX l_tab_lines.

lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).

lt_objpack-transf_bin = 'X'.

lt_objpack-head_start = 1.

lt_objpack-head_num = 0.

lt_objpack-body_start = 1.

lt_objpack-body_num = l_tab_lines.

lt_objpack-doc_type = l_att_type.

lt_objpack-obj_name = 'ATTACHMENT'.

lt_objpack-obj_descr = 'Resume'.

APPEND lt_objpack.

<b>* Create receiver list</b>

lt_reclist-receiver = 'pragyavatsa@ko-india.com'.

lt_reclist-rec_type = 'U'.

APPEND lt_reclist.

<b>* Send Message</b>

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = ls_docdata

put_in_outbox = ''

TABLES

packing_list = lt_objpack

object_header = lt_objhead

contents_bin = lt_objbin

contents_txt = lt_objtxt

receivers = lt_reclist

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.

  • Document sent

MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.

ELSE.

  • Document <&> could not be sent

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH ls_docdata-obj_name.

ENDIF.

-


<b>END OF PROGRAM</b>----


Can anybody tell me where I am making mistake?

Thanks in advance,

Pragya

Tags:
Former Member
Former Member replied

Hi pragya,

1. <b>Very MINOR MISTAKE</b>.

2. <b>commit_work = 'X'</b>

3. pass this parameter also

while calling

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

4. <b>Now it will work.</b>

regards,

amit m.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question