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 two attachments in one mail

Former Member
0 Kudos

Dear all,


     I am fresher in ABAP . Now I am developing a mail alert program , in this process I am facing one problem . my problem is sending two attachments in one mail , it is not working , but I have send one attachment successfully . Please help me.


My first attachment final table is it_bsis1.

My second attachment final table is it_bsis2.


My code is in bellow attachment.

For adjustment of file size I have delete some code.


Regards,

Srikanth.

3 REPLIES 3

Former Member
0 Kudos

Hi srikantareddy ,

Follow the steps mentioned below:

Step 1: Create an FM in SE37

FUNCTION z_send_email.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(SUBJECT) TYPE  SO_OBJ_DES

*"     VALUE(MESSAGE_BODY) TYPE  BCSY_TEXT

*"     VALUE(ATTACHMENTS) TYPE  RMPS_T_POST_CONTENT OPTIONAL

*"     VALUE(SENDER_UID) TYPE  SYUNAME OPTIONAL

*"     VALUE(RECIPIENT_UID) TYPE  SYUNAME OPTIONAL

*"     VALUE(SENDER_MAIL) TYPE  ADR6-SMTP_ADDR OPTIONAL

*"     VALUE(RECIPIENT_MAIL) TYPE  ADR6-SMTP_ADDR OPTIONAL

*"  EXPORTING

*"     VALUE(RESULT) TYPE  BOOLEAN

*"  TABLES

*"      RECIPIENTS STRUCTURE  UIYS_IUSR OPTIONAL

*"----------------------------------------------------------------------

*Data Declaration

   DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,

           l_send TYPE adr6-smtp_addr ,

           l_rec TYPE  adr6-smtp_addr .

   DATA : itab TYPE TABLE OF sval,

          ls_itab TYPE sval,

          i_return.

   DATA:

   lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

*     DATA:

*    lt_message_body TYPE bcsy_text VALUE IS INITIAL,

   DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL,

   attachment_subject TYPE so_obj_des.

   DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.

   DATA: ls_recipient LIKE LINE OF recipients,

   ls_attachment LIKE LINE OF attachments.

   DATA: lv_recipient_uid TYPE uname,

         lv_recipient_mail TYPE adr6-smtp_addr.

*Prepare Mail Object

   CLASS cl_bcs DEFINITION LOAD.

   lo_send_request = cl_bcs=>create_persistent( ).

* Message body and subject

   DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.

   lo_document = cl_document_bcs=>create_document(

   i_type = 'RAW'

   i_text =  message_body

   i_subject = subject ).

*Send  attachment

   LOOP AT attachments INTO ls_attachment.

     attachment_subject = ls_attachment-subject.

     TRY.

         lo_document->add_attachment(

         EXPORTING

         i_attachment_type = ls_attachment-objtp

         i_attachment_subject = attachment_subject

         i_att_content_hex = ls_attachment-cont_hex ).

       CATCH cx_document_bcs INTO lx_document_bcs.

     ENDTRY.

   ENDLOOP.

* Pass the document to send request

   lo_send_request->set_document( lo_document ).

   TRY.

       IF sender_mail IS NOT INITIAL.

         lo_sender = cl_cam_address_bcs=>create_internet_address( sender_mail ).

       ELSEIF sender_uid IS NOT INITIAL.

         lo_sender = cl_sapuser_bcs=>create( sender_uid ).

       ELSE.

         lo_sender = cl_sapuser_bcs=>create( sy-uname ).

       ENDIF.

* Set sender

       lo_send_request->set_sender(

       EXPORTING

       i_sender = lo_sender ).

     CATCH cx_address_bcs.

       RETURN.

   ENDTRY.

* Set  recipients

   IF recipients[] IS INITIAL.

     IF recipient_mail IS NOT INITIAL.

       lo_recipient = cl_cam_address_bcs=>create_internet_address( recipient_mail ).

     ELSEIF recipient_uid IS NOT INITIAL.

       lo_recipient = cl_sapuser_bcs=>create( recipient_uid ).

     ELSE.

       lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

     ENDIF.

     lo_send_request->add_recipient(

     EXPORTING

     i_recipient = lo_recipient

     i_express = 'X' ).

   ELSE.

     LOOP AT recipients INTO ls_recipient.

       IF ls_recipient-iusrid IS NOT INITIAL.

         lv_recipient_uid = ls_recipient-iusrid.

         lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ).

       ELSEIF ls_recipient-email IS NOT INITIAL.

         lv_recipient_mail = ls_recipient-email .

         lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_recipient_mail ).

       ENDIF.

       lo_send_request->add_recipient(

           EXPORTING

           i_recipient = lo_recipient

           i_express = 'X' ).

     ENDLOOP.

   ENDIF.

   TRY.

** Send email

       lo_send_request->send(

       EXPORTING

       i_with_error_screen = 'X'

       RECEIVING

       result = result ).

       COMMIT WORK.

       WAIT UP TO 1 SECONDS.

     CATCH cx_send_req_bcs.

       result = ''.

   ENDTRY.

ENDFUNCTION.

step2: Write the logic in the program (You have followed this for one document , do the same for the other one )
           Concatenate it_bsis1 into ls_attachment.
           Append ls_attachment to lt_attachment.

           Concatenate it_bsis1 into ls_attachment.

           Append ls_attachment to lt_attachment.

step3 : Call the Fm in program

CALL FUNCTION 'Z_SEND_EMAIL'

       EXPORTING

         subject        = lv_text_subject

         message_body   = lt_body

         attachments    = lt_attachments

         sender_mail    = psender

         recipient_mail = lv_recipient_mail

       TABLES

         recipients     = lt_recipients.

0 Kudos

Dear Farid Hasan,

    Thank you very much for replay , I will try.

Regards,

Srikanth.

Former Member