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 mial using SO_NEW_DOCUMENT_SEND_API1 :getting error

Former Member
0 Kudos

HI Experts ,

Plz help me i am taking sample program in this FM but unable to send mial .

my mial id needs any configuration is needed.

Thanks

1 ACCEPTED SOLUTION

former_member195383
Active Contributor
0 Kudos

Hi

Scott settings need to be maintained for this. Basis guys will take care of this. get in touch with them

Also in debugging mode check the sy-subrc value of after the FMs execution.

If sy-subrc is 0 then check your SAP outbox. If the mail is present there then

again basis has the responsibility to send it from there to your mailid.

Regards

Rudra

7 REPLIES 7

former_member195383
Active Contributor
0 Kudos

Hi

Scott settings need to be maintained for this. Basis guys will take care of this. get in touch with them

Also in debugging mode check the sy-subrc value of after the FMs execution.

If sy-subrc is 0 then check your SAP outbox. If the mail is present there then

again basis has the responsibility to send it from there to your mailid.

Regards

Rudra

0 Kudos

Thanks Prasanna,

scott settings are mandatory to send a mail to outside ? and we are getting sy-subrc = 2 .

that means document not send to any recepient.

0 Kudos

Yes those settings are mandatory

Former Member
0 Kudos

hi,

Check this Code...

DATA: l_tab_lines TYPE i,
        l_string TYPE char300,
        l_line TYPE string.

  CONSTANTS : l_c_255(255)  TYPE c VALUE '255',
              l_c_txt(3)    TYPE c VALUE 'TXT'.

  DATA: lt_reclist  TYPE STANDARD TABLE OF somlreci1,       "Recipients
        lt_objpack  TYPE STANDARD TABLE OF sopcklsti1,
        lt_objhead  TYPE STANDARD TABLE OF solisti1,
        lt_objtxt   TYPE STANDARD TABLE OF solisti1,     "Body of EMail
        lt_objbin   TYPE STANDARD TABLE OF solisti1."Attachment of EMail

  DATA: l_doc_chng TYPE sodocchgi1,     "attributes of document to send
        l_reclist  LIKE LINE OF lt_reclist,
        l_objpack  LIKE LINE OF lt_objpack,
        l_obj      LIKE LINE OF lt_objhead.

  DATA :
    l_hex LIKE solix,
    lt_contents_hex LIKE STANDARD TABLE OF solix ,
    conv TYPE REF TO cl_abap_conv_out_ce,
    l_buffer TYPE xstring,
    l_hexa(510) TYPE x.

* Completing the recipient list
  l_reclist-receiver = p_emailid.           " Email id
  l_reclist-express  = 'X'.
  l_reclist-rec_type = 'U'.
  APPEND l_reclist TO lt_reclist.
  CLEAR  l_reclist.


* Body of Email Message
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line
  l_obj-line = 'Hello,'(012).
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.

  l_obj-line = cl_abap_char_utilities=>newline.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line

  CONCATENATE
   'Please click the link to acess the Confirmation Form.'(t01)
   'Kindly complete the same and return it to the HR contact 15 days' &
   ' prior to the date of confirmation of the employee.'(t02)
               INTO l_obj-line SEPARATED BY space.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.

  l_obj-line = cl_abap_char_utilities=>newline.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line

  CONCATENATE text-l01 text-l02 INTO l_obj-line.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.

  l_obj-line = cl_abap_char_utilities=>newline.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line

  l_obj-line =
  'For Trainees use Confirmation form trainees and for rest use the' &
  ' Confirmation form.'(t03).
  APPEND l_obj TO lt_objtxt.
  CLEAR l_obj.


  l_obj-line = cl_abap_char_utilities=>newline.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line

  l_obj-line = 'The details of the employee are as follows :'(017).
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.

  l_obj-line = cl_abap_char_utilities=>newline.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.       " Blank line


  l_obj-line = 'Name'(013).
  l_obj-line+60 = 'Department'(005).
  l_obj-line+128 = 'DOJ'(014).
  l_obj-line+150 = 'Confirmation Date'(015).
*  CONCATENATE 'Name'(013)
*              'Department'(005)
*              'DOJ'(014)
*              'Confirmation Date'(015)
*            INTO l_obj-line
*       SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
  APPEND l_obj TO lt_objtxt.   CLEAR l_obj.

* Email Attachment
* Append headings
  CONCATENATE 'Empployee No.'(002)
              'Employee Group'(016)
              'Employee Name'(001)
              'Designation'(003)
              'Joining Date'(004)
              'Department'(005)
              'Branch/Location'(006)
              'Unit'(007)
              'Confirmation Due'(008)
              'Form sent on'(009)
              'Form Return by'(010)
              'Employee Group'(016)
            INTO l_string
       SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
  APPEND l_string TO lt_objbin.
  CLEAR l_string.

  APPEND INITIAL LINE TO lt_objbin.

  LOOP AT p_emp_details INTO i_emp_details_line.
    CONCATENATE i_emp_details_line-pnalt
                i_emp_details_line-egroup
                i_emp_details_line-ename
                i_emp_details_line-stext
                i_emp_details_line-srvdt
                i_emp_details_line-ltext
                i_emp_details_line-pbtxt
                i_emp_details_line-btrtx
                i_emp_details_line-mndat
                i_emp_details_line-fsdate
                i_emp_details_line-frdate
                i_emp_details_line-egroup
           INTO l_string
      SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
*    CONCATENATE l_string cl_abap_char_utilities=>horizontal_tab
*               INTO l_string.
    APPEND l_string TO lt_objbin.
    CLEAR l_string.

    l_obj-line = i_emp_details_line-ename.
    l_obj-line+60 = i_emp_details_line-ltext.
    l_obj-line+128 = i_emp_details_line-srvdt.
    l_obj-line+150 = i_emp_details_line-mndat.

*    CONCATENATE i_emp_details_line-ename
*                i_emp_details_line-ltext
*                i_emp_details_line-srvdt
*                i_emp_details_line-mndat
*            INTO l_obj-line
*       SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
    APPEND l_obj TO lt_objtxt.   CLEAR l_obj.


  ENDLOOP.

  IF r_cprob EQ 'X'.
    l_string = 'Completion of probation List'(029).
  ELSE.
    l_string = 'Completion of extension of probation List'(018).
  ENDIF.
  APPEND l_string TO lt_objhead.

* APPEND object_header.
  CALL FUNCTION 'SO_RAW_TO_RTF'
    TABLES
      objcont_old = lt_objbin
      objcont_new = lt_objbin.

  LOOP AT lt_objbin INTO l_line.
   conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'B').
    CALL METHOD conv->write( data = l_line ).
    l_buffer = conv->get_buffer( ).
    MOVE l_buffer TO l_hexa.
    MOVE l_hexa TO l_hex-line.
    APPEND l_hex TO lt_contents_hex.
  ENDLOOP.

* File name for attachment
  CONCATENATE 'Completion of extension of probation List'(018)
               sy-datum '.XLS' INTO l_obj SEPARATED BY space.
  APPEND l_obj TO lt_objhead.

* Email Body Details
  CLEAR l_tab_lines.
  DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
  l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 +
                          STRLEN( l_string ).  "size of doc in bytes
  l_doc_chng-obj_name = sy-repid.
  l_doc_chng-obj_langu = sy-langu.
  l_doc_chng-obj_descr = 'Completion of extension of probation'(s05).
  l_doc_chng-sensitivty = 'P'.          "  Send mail as a confidential

  l_objpack-head_start = 1.
  l_objpack-head_num   = 1.
  l_objpack-body_start = 1.
  l_objpack-body_num   = l_tab_lines.
  l_objpack-doc_type   = l_c_txt.
  APPEND l_objpack TO lt_objpack.
  CLEAR  l_objpack.

* Email Attachment Details
  CLEAR l_tab_lines.
  DESCRIBE TABLE lt_objbin LINES l_tab_lines.
* Creation of the entry for the compressed attachment
  l_objpack-transf_bin = 'X'.
  l_objpack-head_start = 1.
  l_objpack-head_num   = 1.
  l_objpack-body_start = 1.
  l_objpack-doc_type   = 'XLS'.
  l_objpack-obj_name   = l_obj.
  l_objpack-obj_descr  = l_obj.
  l_objpack-body_num   = l_tab_lines.
  l_objpack-doc_size   = l_tab_lines * l_c_255.
  APPEND l_objpack TO lt_objpack.
  CLEAR  l_objpack.

* Send the document
  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = l_doc_chng
      put_in_outbox              = ' '
      commit_work                = 'X'
    TABLES
      packing_list               = lt_objpack
      object_header              = lt_objhead
*      contents_bin               = lt_objbin
      contents_txt               = lt_objtxt
      contents_hex               = lt_contents_hex
      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.
    MESSAGE s000(oo) WITH 'Email sent to recipients'(019).
*   To refresh SAP Work Office so that mail can be recieved immediataly.
    SUBMIT rsconn01 WITH mode = 'INT'
                  WITH output = ''
                  AND RETURN.

*   Update the infotype 0019 after sending the email with the status
*   u2018Task in processu2018 from u2018Task in processu2018.
    PERFORM update_0019 TABLES p_emp_details.

  ELSE.
    MESSAGE s000(oo) WITH 'Problem in sending Email.'(e01).
  ENDIF.

agnihotro_sinha2
Active Contributor
0 Kudos
 
data:   lwa_objpack type sopcklsti1,        "Contents of the Email
          li_objpack type standard table of sopcklsti1,
          lwa_reclist type somlreci1,         "Recievers List
          li_reclist type standard table of somlreci1,
          lwa_doc_chng type sodocchgi1,        "Mail Contents
          lv_line  like sy-tabix,     "Email Params
          objtxt  like solisti1   occurs 10 with header line.


  constants : lc_space type c value ' ',
              lc_1(15) type n value '1',         "Email Params
              lc_raw(3) type c value 'RAW',       "Email Params
              lc_u type c value 'U',              "Recipient Property
              lc_01 type c value '1',
              lc_x type c value 'X'.

clear: p_subject, p_msg, p_mail.

*  Filling Mail Contents
  lwa_doc_chng-obj_name = 'E-Mail'.
  lwa_doc_chng-obj_descr = 'Your Appointment has been booked'.

  objtxt = 'Hello ABC ,'.
  append objtxt.

   objtxt = 'BOOKING ID: AND171008330BAN'.
  append objtxt.

  objtxt = 'Your appointment is being booked with Dr.Andrew at Memorial Hospital 17-10-2008 at 3:30PM. Please produce this booking ID at the time of consultation'.
  append objtxt.

  objtxt = '     '.
  append objtxt.

  objtxt = 'Thanks and Regards'.
  append objtxt.

  objtxt = 'Appointment booking team'.
  append objtxt.

  describe table objtxt lines lv_line.

   read table objtxt index lv_line transporting no fields.
  lwa_doc_chng-doc_size = ( lv_line - 1 ) * 255 + strlen( objtxt ).


*  Pack to main body
  lwa_objpack-body_start =  lc_1.
  lwa_objpack-head_start = lc_1.
  lwa_objpack-head_num   = '0'.
  lwa_objpack-body_num   =  lv_line.
  lwa_objpack-doc_type   =  lc_raw.
  append lwa_objpack to li_objpack.



  translate p_mail to lower case.


*  Fill receiver list
  lwa_reclist-receiver     =  'abc at xyz.com'. "Email id
  lwa_reclist-rec_type     =  lc_u.
  append lwa_reclist to li_reclist.

call function 'SO_DOCUMENT_SEND_API1'
  exporting
    document_data                    = lwa_doc_chng
   put_in_outbox                    = lc_x
   commit_work                      = lc_x
  tables
    packing_list                     = li_objpack
   contents_txt                     = objtxt
    receivers                        = li_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.
 message id sy-msgid type sy-msgty number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

if sy-subrc = 0.
    call function 'BAPI_TRANSACTION_COMMIT'.
  endif.


ENDFUNCTION.

Former Member
0 Kudos

Hi kalyan,

Check this blog

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Regards

Former Member
0 Kudos

Thanks to all