<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872057#M1323444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Adrian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if you can make head or tail to this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_attachments.
        INCLUDE STRUCTURE sopcklsti1.
TYPES: END    OF ty_attachments.
TYPES: ty_t_attachments   TYPE TABLE OF ty_attachments INITIAL SIZE 10.

*Table with data on each attachment.
DATA: gt_attachments  TYPE ty_t_attachments.

*Structure - mainly for the Email subject.
DATA: gs_doc_data     TYPE sodocchgi1.

*Email object number.
DATA: gs_object_id    TYPE sofolenti1-object_id.

*Table of recipient list.
DATA: gt_recivers     TYPE TABLE OF somlreci1 INITIAL SIZE 0.

*Table of the Email content (body).
DATA: gt_content      TYPE soli_tab.

*Table of email details.
DATA: gt_objpack      TYPE TABLE OF sopcklsti1 INITIAL SIZE 2.

*
DATA: gv_sender_addr      TYPE  soextreci1-receiver,
      gv_sender_addr_type TYPE  soextreci1-adr_typ.

*Table that contain the attachment data.
*************
* NOTE: It has to be converted using FM 'SO_RAW_TO_RTF' before sending.
*************
TYPES: ty_t_text_tab  TYPE TABLE OF solisti1 INITIAL SIZE 0.
DATA: gt_text_tab     TYPE ty_t_text_tab.

FORM send_email_with_attachment_new
                          USING    pv_file_type   TYPE sopcklsti1-doc_type
                                   pv_file_name   TYPE sopcklsti1-obj_name
                                   pv_file_desc   TYPE sopcklsti1-obj_descr
                                   pv_ok_msg      TYPE abap_bool
                                   pv_err_msg     TYPE abap_bool
                          CHANGING pv_error_no    TYPE bcs_cxerr.

  DATA: lc_send_request   TYPE REF TO cl_bcs,
        lc_document       TYPE REF TO cl_document_bcs,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: lv_sent_to_all    TYPE os_boolean,
        lv_att_subject    TYPE sood-objdes.

* If no recievers were set - don't process.
  IF gt_recivers[] IS INITIAL.
    IF pv_err_msg = 'X'.
      MESSAGE i032(y1) WITH 'Mail not sent - no receivers set'(a57).
    ELSE.
      pv_error_no = 1.
    ENDIF.

    RETURN.
  ENDIF.

  TRY.
*     Create the send request.
      lc_send_request = cl_bcs=&amp;gt;create_persistent( ).

*     Add recipients in a loop.
      PERFORM add_recipients
                          USING lc_send_request
                                pv_err_msg
                                pv_error_no.
      CHECK pv_error_no IS INITIAL.

*     Set email body.
      PERFORM create_email_body
                          USING lc_document
                                pv_err_msg
                                pv_error_no.
      CHECK pv_error_no IS INITIAL.

*     add list attachment to document
      lv_att_subject = pv_file_desc.
      lc_document-&amp;gt;add_attachment( i_attachment_type    = pv_file_type
                                   i_attachment_subject = lv_att_subject
                                   i_att_content_text   = gt_text_tab ).

*     Add document to send request.
      lc_send_request-&amp;gt;set_document( lc_document ).

*     Send the mail.
      lv_sent_to_all = lc_send_request-&amp;gt;send( i_with_error_screen = 'X' ).

*     If all OK and message flag is on - issue message.
      IF lv_sent_to_all = 'X'.
        IF pv_ok_msg = 'X'.
          MESSAGE i032(y1) WITH 'Email with attachment sent OK'(a59).
        ELSE.
          pv_error_no = 0.
        ENDIF.
      ENDIF.
    CATCH cx_bcs INTO lf_bcs_exception.
      IF pv_err_msg = 'X'.
        MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception-&amp;gt;error_type
                              'encountered when sending email.'(a56).
      ELSE.
        pv_error_no = lf_bcs_exception-&amp;gt;error_type.
      ENDIF.
  ENDTRY.

* Mails with BCS requires COMMIT.
  COMMIT WORK.
ENDFORM.                    "send_email_with_attachment_new

FORM add_recipients
                USING pc_send_request TYPE REF TO cl_bcs
                      pv_err_msg      TYPE abp_fform
                      pv_error_no     TYPE bcs_cxerr.

  DATA: lf_recipient      TYPE REF TO if_recipient_bcs,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: ls_recivers       TYPE somlreci1.
  DATA: adr6-smtp_addr    TYPE adr6-smtp_addr.

* Initiate error flag.
  CLEAR: pv_error_no.

* If no recievers were set - don't process.
  IF gt_recivers[] IS INITIAL.
    IF pv_err_msg = 'X'.
      MESSAGE i000(y1) WITH 'Mail not sent - no receivers set'(a57).
    ELSE.
      pv_error_no = 1.
    ENDIF.

    RETURN.
  ENDIF.

  LOOP AT gt_recivers INTO ls_recivers.
    adr6-smtp_addr = ls_recivers-receiver.
    TRY.
        lf_recipient = cl_cam_address_bcs=&amp;gt;create_internet_address( adr6-smtp_addr ).
        pc_send_request-&amp;gt;add_recipient( i_recipient = lf_recipient ).

      CATCH cx_bcs INTO lf_bcs_exception.
        IF pv_err_msg = 'X'.
          MESSAGE i000(y1) WITH 'Error number' lf_bcs_exception-&amp;gt;error_type
                                'encountered when adding recipient.'.
        ELSE.
          pv_error_no = 2.
        ENDIF.
    ENDTRY.
  ENDLOOP.
ENDFORM.                    "Add_Recipients

FORM create_email_body
                USING pc_document     TYPE REF TO cl_document_bcs
                      pv_err_msg      TYPE abp_fform
                      pv_error_no     TYPE bcs_cxerr.

  DATA: ls_content        TYPE soli,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: lv_mail_subject   TYPE so_obj_des,
        lv_i_type         TYPE so_obj_tp.

* Initiate error flag.
  CLEAR: pv_error_no.

* Convert Mail subject to BCS type.
  lv_mail_subject = gs_doc_data-obj_descr.

  TRY.
*     Create without Email body.
      IF gt_content[] IS INITIAL.
        pc_document = cl_document_bcs=&amp;gt;create_document(
                                  i_type    = 'RAW'
                                  i_subject = lv_mail_subject ).
        EXIT.
      ENDIF.

*     Check if GT_CONTENT have HTML code and set type accordingly.
      READ TABLE gt_content INTO ls_content INDEX 1.
      IF ls_content-line CS '&amp;lt;HTML&amp;gt;'.
        lv_i_type = 'HTM'.
      ELSE.
        lv_i_type = 'RAW'.
      ENDIF.

*     Create email's body.
      pc_document = cl_document_bcs=&amp;gt;create_document(
                                i_type    = lv_i_type
                                i_text    = gt_content
                                i_subject = lv_mail_subject ).

    CATCH cx_bcs INTO lf_bcs_exception.
      IF pv_err_msg = 'X'.
        MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception-&amp;gt;error_type
                              'encountered when creating email body.'(a60).
      ELSE.
        pv_error_no = 3.
      ENDIF.
  ENDTRY.
ENDFORM.                    "Set_Email_Body&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if this can help.&lt;/P&gt;&lt;P&gt;Ayal Telem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 02 Aug 2009 09:51:09 GMT</pubDate>
    <dc:creator>yes_sapteam</dc:creator>
    <dc:date>2009-08-02T09:51:09Z</dc:date>
    <item>
      <title>Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872051#M1323438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a more recent functionality for sending email? One with a simpler interface? If yes, please post example code. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2009 09:49:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872051#M1323438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-08T09:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872052#M1323439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at these example programs ,&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_1&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_2&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_3&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_4&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_5&lt;/P&gt;&lt;P&gt;BCS_EXAMPLE_6.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2009 09:54:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872052#M1323439</guid>
      <dc:creator>huseyindereli</dc:creator>
      <dc:date>2009-07-08T09:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872053#M1323440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Search SCN.you can find solutions to your requirement .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Aakash Banga&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2009 09:58:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872053#M1323440</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-08T09:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872054#M1323441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check with the below example for sending mail with the same FM if ur not able to achieve with this otherwise you have to check in SDN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  elseif ls_control_param-preview is initial and&lt;/P&gt;&lt;P&gt;   ls_control_param-getotf is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; ls_control_param-GETOTF = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; ls_control_param-NO_DIALOG = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL FUNCTION v_form_name&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;      archive_index      = toa_dara&lt;/P&gt;&lt;P&gt;      archive_parameters = arc_params&lt;/P&gt;&lt;P&gt;      control_parameters = ls_control_param&lt;/P&gt;&lt;P&gt;      mail_recipient     = ls_recipient&lt;/P&gt;&lt;P&gt;      mail_sender        = ls_sender&lt;/P&gt;&lt;P&gt;      output_options     = ls_composer_param&lt;/P&gt;&lt;P&gt;      is_ekko            = l_doc-xekko&lt;/P&gt;&lt;P&gt;      user_settings      = ' '"iv_user_settings  "Disable User Printer&lt;/P&gt;&lt;P&gt;      is_pekko           = l_doc-xpekko&lt;/P&gt;&lt;P&gt;      is_nast            = l_nast&lt;/P&gt;&lt;P&gt;      iv_from_mem        = l_from_memory&lt;/P&gt;&lt;P&gt;      iv_druvo           = iv_druvo&lt;/P&gt;&lt;P&gt;      iv_xfz             = iv_xfz&lt;/P&gt;&lt;P&gt;    IMPORTING&lt;/P&gt;&lt;P&gt;      JOB_OUTPUT_INFO    = w_return&lt;/P&gt;&lt;P&gt;      EV_ADDNR_VENDOR    = IV_ADDNR_VENDOR&lt;/P&gt;&lt;P&gt;    TABLES&lt;/P&gt;&lt;P&gt;      it_ekpo            = l_doc-xekpo[]&lt;/P&gt;&lt;P&gt;      it_ekpa            = l_doc-xekpa[]&lt;/P&gt;&lt;P&gt;      it_pekpo           = l_doc-xpekpo[]&lt;/P&gt;&lt;P&gt;      it_eket            = l_doc-xeket[]&lt;/P&gt;&lt;P&gt;      it_tkomv           = l_doc-xtkomv[]&lt;/P&gt;&lt;P&gt;      it_ekkn            = l_doc-xekkn[]&lt;/P&gt;&lt;P&gt;      it_ekek            = l_doc-xekek[]&lt;/P&gt;&lt;P&gt;      it_komk            = l_xkomk[]&lt;/P&gt;&lt;P&gt;    EXCEPTIONS&lt;/P&gt;&lt;P&gt;      formatting_error   = 1&lt;/P&gt;&lt;P&gt;      internal_error     = 2&lt;/P&gt;&lt;P&gt;      send_error         = 3&lt;/P&gt;&lt;P&gt;      user_canceled      = 4&lt;/P&gt;&lt;P&gt;      OTHERS             = 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;    ent_retco = sy-subrc.&lt;/P&gt;&lt;P&gt;    PERFORM protocol_update_i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;get SmartForm protocoll and store it in the NAST protocoll&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    PERFORM add_smfrm_prot.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; CALL FUNCTION 'FP_JOB_CLOSE'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; ELSE.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   IF OUT-PREVIEW = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i_otf[] = w_return-otfdata[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call function 'CONVERT_OTF'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;format = 'PDF'&lt;/P&gt;&lt;P&gt;max_linewidth = 132&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;bin_filesize = v_len_in&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;otf = i_otf&lt;/P&gt;&lt;P&gt;lines = i_tline&lt;/P&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;P&gt;err_max_linewidth = 1&lt;/P&gt;&lt;P&gt;err_format = 2&lt;/P&gt;&lt;P&gt;err_conv_not_possible = 3&lt;/P&gt;&lt;P&gt;others = 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Fehlerhandling&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_tline.&lt;/P&gt;&lt;P&gt;translate i_tline using '~'.&lt;/P&gt;&lt;P&gt;concatenate wa_buffer i_tline into wa_buffer.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;translate wa_buffer using '~'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do.&lt;/P&gt;&lt;P&gt;i_record = wa_buffer.&lt;/P&gt;&lt;P&gt;append i_record.&lt;/P&gt;&lt;P&gt;shift wa_buffer left by 255 places.&lt;/P&gt;&lt;P&gt;if wa_buffer is initial.&lt;/P&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;enddo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data iv_mailid type AD_SMTPADR.&lt;/P&gt;&lt;P&gt;select single SMTP_ADDR from ADR6 into iv_mailid where ADDRNUMBER =&lt;/P&gt;&lt;P&gt;IV_ADDNR_VENDOR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Attachment&lt;/P&gt;&lt;P&gt;refresh:&lt;/P&gt;&lt;P&gt;i_reclist,&lt;/P&gt;&lt;P&gt;i_objtxt,&lt;/P&gt;&lt;P&gt;i_objbin,&lt;/P&gt;&lt;P&gt;i_objpack.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear wa_objhead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i_objbin[] = i_record[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Create Message Body&lt;/P&gt;&lt;P&gt;*Title and Description&lt;/P&gt;&lt;P&gt;*************i_objtxt = 'test with pdf-Attachment!'.&lt;/P&gt;&lt;P&gt;*************append i_objtxt.&lt;/P&gt;&lt;P&gt;describe table i_objtxt lines v_lines_txt.&lt;/P&gt;&lt;P&gt;read table i_objtxt index v_lines_txt.&lt;/P&gt;&lt;P&gt;wa_doc_chng-obj_name = 'smartform'.&lt;/P&gt;&lt;P&gt;wa_doc_chng-expiry_dat = sy-datum + 10.&lt;/P&gt;&lt;P&gt;wa_doc_chng-obj_descr = 'smartform'.&lt;/P&gt;&lt;P&gt;wa_doc_chng-sensitivty = 'F'.&lt;/P&gt;&lt;P&gt;wa_doc_chng-doc_size = v_lines_txt * 255.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Main Text&lt;/P&gt;&lt;P&gt;*wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )&lt;/P&gt;&lt;P&gt;*.&lt;/P&gt;&lt;P&gt;clear i_objpack-transf_bin.&lt;/P&gt;&lt;P&gt;*i_objpack-head_start = 1.&lt;/P&gt;&lt;P&gt;*i_objpack-head_num = 0.&lt;/P&gt;&lt;P&gt;*i_objpack-body_start = 1.&lt;/P&gt;&lt;P&gt;*i_objpack-body_num = v_lines_txt.&lt;/P&gt;&lt;P&gt;*i_objpack-doc_type = 'RAW'.&lt;/P&gt;&lt;P&gt;*append i_objpack.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Attachment&lt;/P&gt;&lt;P&gt;*(pdf-Attachment)&lt;/P&gt;&lt;P&gt;i_objpack-transf_bin = 'X'.&lt;/P&gt;&lt;P&gt;*i_objpack-head_start = 1.&lt;/P&gt;&lt;P&gt;i_objpack-head_num = 0.&lt;/P&gt;&lt;P&gt;i_objpack-body_start = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Länge des Attachment ermitteln&lt;/P&gt;&lt;P&gt;describe table i_objbin lines v_lines_bin.&lt;/P&gt;&lt;P&gt;read table i_objbin index v_lines_bin.&lt;/P&gt;&lt;P&gt;i_objpack-doc_size = v_lines_bin * 255 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i_objpack-body_num = v_lines_bin.&lt;/P&gt;&lt;P&gt;i_objpack-doc_type = 'PDF'.&lt;/P&gt;&lt;P&gt;i_objpack-obj_name = 'smart'.&lt;/P&gt;&lt;P&gt;i_objpack-obj_descr = 'test'.&lt;/P&gt;&lt;P&gt;append i_objpack.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear i_reclist.&lt;/P&gt;&lt;P&gt;i_reclist-receiver = iv_mailid.&lt;/P&gt;&lt;P&gt;i_reclist-rec_type = 'U'.&lt;/P&gt;&lt;P&gt;append i_reclist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;document_data = wa_doc_chng&lt;/P&gt;&lt;P&gt;put_in_outbox = 'X'&lt;/P&gt;&lt;P&gt;COMMIT_WORK   = 'X'&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;packing_list = i_objpack&lt;/P&gt;&lt;P&gt;*object_header = wa_objhead&lt;/P&gt;&lt;P&gt;CONTENTS_BIN = i_objbin&lt;/P&gt;&lt;P&gt;contents_txt = i_objtxt&lt;/P&gt;&lt;P&gt;receivers = i_reclist&lt;/P&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;P&gt;too_many_receivers = 1&lt;/P&gt;&lt;P&gt;document_not_sent = 2&lt;/P&gt;&lt;P&gt;document_type_not_exist = 3&lt;/P&gt;&lt;P&gt;operation_no_authorization = 4&lt;/P&gt;&lt;P&gt;parameter_error = 5&lt;/P&gt;&lt;P&gt;x_error = 6&lt;/P&gt;&lt;P&gt;enqueue_error = 7&lt;/P&gt;&lt;P&gt;others = 8.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt; MESSAGE 'Mail was not sent' type 'E'.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;  MESSAGE 'Mail was sent Succesfully' type 'S'.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2009 10:09:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872054#M1323441</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-08T10:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872055#M1323442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use this class &lt;STRONG&gt;CL_BCS&lt;/STRONG&gt;  and also &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2009 10:42:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872055#M1323442</guid>
      <dc:creator>vijy_mukunthan</dc:creator>
      <dc:date>2009-07-08T10:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872056#M1323443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seriously Aakash, don't waste your time or mine with meaningless responses. If I could find something useful, I wouldn't have posted this question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2009 05:50:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872056#M1323443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-02T05:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replacement for SO_NEW_DOCUMENT_ATT_SEND_API1?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872057#M1323444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Adrian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if you can make head or tail to this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_attachments.
        INCLUDE STRUCTURE sopcklsti1.
TYPES: END    OF ty_attachments.
TYPES: ty_t_attachments   TYPE TABLE OF ty_attachments INITIAL SIZE 10.

*Table with data on each attachment.
DATA: gt_attachments  TYPE ty_t_attachments.

*Structure - mainly for the Email subject.
DATA: gs_doc_data     TYPE sodocchgi1.

*Email object number.
DATA: gs_object_id    TYPE sofolenti1-object_id.

*Table of recipient list.
DATA: gt_recivers     TYPE TABLE OF somlreci1 INITIAL SIZE 0.

*Table of the Email content (body).
DATA: gt_content      TYPE soli_tab.

*Table of email details.
DATA: gt_objpack      TYPE TABLE OF sopcklsti1 INITIAL SIZE 2.

*
DATA: gv_sender_addr      TYPE  soextreci1-receiver,
      gv_sender_addr_type TYPE  soextreci1-adr_typ.

*Table that contain the attachment data.
*************
* NOTE: It has to be converted using FM 'SO_RAW_TO_RTF' before sending.
*************
TYPES: ty_t_text_tab  TYPE TABLE OF solisti1 INITIAL SIZE 0.
DATA: gt_text_tab     TYPE ty_t_text_tab.

FORM send_email_with_attachment_new
                          USING    pv_file_type   TYPE sopcklsti1-doc_type
                                   pv_file_name   TYPE sopcklsti1-obj_name
                                   pv_file_desc   TYPE sopcklsti1-obj_descr
                                   pv_ok_msg      TYPE abap_bool
                                   pv_err_msg     TYPE abap_bool
                          CHANGING pv_error_no    TYPE bcs_cxerr.

  DATA: lc_send_request   TYPE REF TO cl_bcs,
        lc_document       TYPE REF TO cl_document_bcs,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: lv_sent_to_all    TYPE os_boolean,
        lv_att_subject    TYPE sood-objdes.

* If no recievers were set - don't process.
  IF gt_recivers[] IS INITIAL.
    IF pv_err_msg = 'X'.
      MESSAGE i032(y1) WITH 'Mail not sent - no receivers set'(a57).
    ELSE.
      pv_error_no = 1.
    ENDIF.

    RETURN.
  ENDIF.

  TRY.
*     Create the send request.
      lc_send_request = cl_bcs=&amp;gt;create_persistent( ).

*     Add recipients in a loop.
      PERFORM add_recipients
                          USING lc_send_request
                                pv_err_msg
                                pv_error_no.
      CHECK pv_error_no IS INITIAL.

*     Set email body.
      PERFORM create_email_body
                          USING lc_document
                                pv_err_msg
                                pv_error_no.
      CHECK pv_error_no IS INITIAL.

*     add list attachment to document
      lv_att_subject = pv_file_desc.
      lc_document-&amp;gt;add_attachment( i_attachment_type    = pv_file_type
                                   i_attachment_subject = lv_att_subject
                                   i_att_content_text   = gt_text_tab ).

*     Add document to send request.
      lc_send_request-&amp;gt;set_document( lc_document ).

*     Send the mail.
      lv_sent_to_all = lc_send_request-&amp;gt;send( i_with_error_screen = 'X' ).

*     If all OK and message flag is on - issue message.
      IF lv_sent_to_all = 'X'.
        IF pv_ok_msg = 'X'.
          MESSAGE i032(y1) WITH 'Email with attachment sent OK'(a59).
        ELSE.
          pv_error_no = 0.
        ENDIF.
      ENDIF.
    CATCH cx_bcs INTO lf_bcs_exception.
      IF pv_err_msg = 'X'.
        MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception-&amp;gt;error_type
                              'encountered when sending email.'(a56).
      ELSE.
        pv_error_no = lf_bcs_exception-&amp;gt;error_type.
      ENDIF.
  ENDTRY.

* Mails with BCS requires COMMIT.
  COMMIT WORK.
ENDFORM.                    "send_email_with_attachment_new

FORM add_recipients
                USING pc_send_request TYPE REF TO cl_bcs
                      pv_err_msg      TYPE abp_fform
                      pv_error_no     TYPE bcs_cxerr.

  DATA: lf_recipient      TYPE REF TO if_recipient_bcs,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: ls_recivers       TYPE somlreci1.
  DATA: adr6-smtp_addr    TYPE adr6-smtp_addr.

* Initiate error flag.
  CLEAR: pv_error_no.

* If no recievers were set - don't process.
  IF gt_recivers[] IS INITIAL.
    IF pv_err_msg = 'X'.
      MESSAGE i000(y1) WITH 'Mail not sent - no receivers set'(a57).
    ELSE.
      pv_error_no = 1.
    ENDIF.

    RETURN.
  ENDIF.

  LOOP AT gt_recivers INTO ls_recivers.
    adr6-smtp_addr = ls_recivers-receiver.
    TRY.
        lf_recipient = cl_cam_address_bcs=&amp;gt;create_internet_address( adr6-smtp_addr ).
        pc_send_request-&amp;gt;add_recipient( i_recipient = lf_recipient ).

      CATCH cx_bcs INTO lf_bcs_exception.
        IF pv_err_msg = 'X'.
          MESSAGE i000(y1) WITH 'Error number' lf_bcs_exception-&amp;gt;error_type
                                'encountered when adding recipient.'.
        ELSE.
          pv_error_no = 2.
        ENDIF.
    ENDTRY.
  ENDLOOP.
ENDFORM.                    "Add_Recipients

FORM create_email_body
                USING pc_document     TYPE REF TO cl_document_bcs
                      pv_err_msg      TYPE abp_fform
                      pv_error_no     TYPE bcs_cxerr.

  DATA: ls_content        TYPE soli,
        lf_bcs_exception  TYPE REF TO cx_bcs.
  DATA: lv_mail_subject   TYPE so_obj_des,
        lv_i_type         TYPE so_obj_tp.

* Initiate error flag.
  CLEAR: pv_error_no.

* Convert Mail subject to BCS type.
  lv_mail_subject = gs_doc_data-obj_descr.

  TRY.
*     Create without Email body.
      IF gt_content[] IS INITIAL.
        pc_document = cl_document_bcs=&amp;gt;create_document(
                                  i_type    = 'RAW'
                                  i_subject = lv_mail_subject ).
        EXIT.
      ENDIF.

*     Check if GT_CONTENT have HTML code and set type accordingly.
      READ TABLE gt_content INTO ls_content INDEX 1.
      IF ls_content-line CS '&amp;lt;HTML&amp;gt;'.
        lv_i_type = 'HTM'.
      ELSE.
        lv_i_type = 'RAW'.
      ENDIF.

*     Create email's body.
      pc_document = cl_document_bcs=&amp;gt;create_document(
                                i_type    = lv_i_type
                                i_text    = gt_content
                                i_subject = lv_mail_subject ).

    CATCH cx_bcs INTO lf_bcs_exception.
      IF pv_err_msg = 'X'.
        MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception-&amp;gt;error_type
                              'encountered when creating email body.'(a60).
      ELSE.
        pv_error_no = 3.
      ENDIF.
  ENDTRY.
ENDFORM.                    "Set_Email_Body&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if this can help.&lt;/P&gt;&lt;P&gt;Ayal Telem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2009 09:51:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/replacement-for-so-new-document-att-send-api1/m-p/5872057#M1323444</guid>
      <dc:creator>yes_sapteam</dc:creator>
      <dc:date>2009-08-02T09:51:09Z</dc:date>
    </item>
  </channel>
</rss>

